Day 13/100 – LeetCode Challenge 🚀 Problem: #283 Move Zeroes Difficulty: Easy Language: Java Approach: Repeated Swapping / Zero Bubbling Time Complexity: O(n²) Space Complexity: O(1) 🔍 Key Insight: The goal is to move all **0s to the end** of the array while keeping the **relative order of non-zero elements unchanged**. Instead of creating a new array, the problem requires solving it **in-place**. 🧠 Solution Brief: First counted the total number of zeroes in the array. Then repeatedly traversed the array and whenever a **0** was found, swapped it with the next element. This process gradually pushes all zeroes toward the end of the array while preserving the order of the remaining elements. 📌 What I Learned: Even simple array problems require careful handling of constraints like **in-place modification** and **order preservation**. These problems also highlight the importance of thinking about **time complexity optimizations** for better performance. #LeetCode #Day13 #100DaysOfCode #Java #DSA #Arrays #ProblemSolving #CodingJourney
Move Zeroes to End in Java
More Relevant Posts
-
Day 14/100 – LeetCode Challenge 🚀 Problem: #169 Majority Element Difficulty: Easy Language: Java Approach: Sorting + Middle Element Time Complexity: O(n log n) Space Complexity: O(1) 🔍 Key Insight: The majority element appears **more than ⌊n / 2⌋ times** in the array. If we **sort the array**, the majority element must occupy the **middle position** because it appears more than half of the time. Therefore, the element at index **n/2** will always be the majority element. 🧠 Solution Brief: First sorted the array using `Arrays.sort()`. Since the majority element appears more than half of the array length, it will always be positioned at the middle index. Finally returned `nums[nums.length / 2]` as the majority element. 📌 What I Learned: Understanding problem constraints can simplify the solution significantly. Sometimes a simple observation (like majority occupying the middle after sorting) can avoid more complex implementations. #LeetCode #Day14 #100DaysOfCode #Java #DSA #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 24 📌 Problem: Two Sum II – Input Array Is Sorted 💻 Language: Java 🧠 Concept Used: Two Pointer Technique 🔍 Platform: LeetCode Today’s challenge was to find two numbers in a sorted array that add up to a given target and return their 1-indexed positions. The problem guarantees exactly one valid solution and requires constant extra space. Example: Input: numbers = [2,7,11,15], target = 9 Output: [1,2] Approach: ✔ Use two pointers — one at the start (left) and one at the end (right) ✔ Calculate the sum of both elements ✔ If the sum equals the target → return their indices ✔ If the sum is smaller → move left forward ✔ If the sum is larger → move right backward Time Complexity: O(n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/gcM_dBA7 🔗 Code: https://lnkd.in/gaUrS-Ne #100DaysOfCode #Day24 #Java #DSA #LeetCode #TwoPointers #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 88 - LeetCode Journey Solved LeetCode 24: Swap Nodes in Pairs in Java ✅ This problem is a great exercise in pointer manipulation in linked lists. Instead of changing values, I swapped the actual nodes by carefully adjusting the next pointers. Using a dummy node made the process much cleaner and helped handle edge cases smoothly. Step by step, I swapped pairs while moving forward in the list. Key takeaways: • Deep understanding of pointer manipulation • Importance of dummy node in linked list problems • Clean handling of edge cases • Iterative approach for swapping nodes ✅ All test cases passed ⚡ Efficient O(n) time and O(1) space Linked list problems like this really sharpen your fundamentals 🔥 #LeetCode #DSA #Java #LinkedList #Pointers #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 47/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 448. Find All Numbers Disappeared in an Array Used an in-place marking technique by treating indices as a hash map and marking visited numbers as negative to identify missing elements. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) (excluding output list) Strengthening understanding of array manipulation and in-place hashing tricks. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Solved LeetCode 2839 – Check if Strings Can be Made Equal With Operations I today. In simple terms, we are given two strings and allowed to swap characters only at positions that are 2 indices apart (like index 0 with 2, 1 with 3). So instead of trying all swaps, the idea is to separate characters at even and odd positions and check if both strings have the same characters in those positions. If the frequency of characters matches for even and odd indices separately, then the strings can be made equal. A simple yet interesting problem that improves thinking around patterns and constraints. #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 85 - LeetCode Journey Solved LeetCode 1721: Swapping Nodes in a Linked List in Java ✅ This problem looks tricky at first, but the idea becomes simple once you break it down. Instead of swapping nodes directly (which can get messy in linked lists), I swapped the values of the nodes. First, I moved to the k-th node from the start. Then using a second pointer and a fast pointer, I found the k-th node from the end in a single pass. Clean approach, no extra space, and efficient traversal. Key takeaways: • Smart use of two-pointer technique • Avoiding complex pointer manipulation by swapping values • Single pass solution after locating first node • Strong grip on linked list traversal ✅ All test cases passed ⚡ Optimized and clean implementation Problems like this really improve your confidence in linked lists 💯 #LeetCode #DSA #Java #LinkedList #TwoPointers #CodingJourney #ProblemSolving #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 7 / 100 – LeetCode Challenge Today I solved Length of Last Word (LeetCode #58) using Java. 🔹 Problem: Given a string "s" containing words and spaces, return the length of the last word in the string. 📌 Approach: - Traverse the string from the end. - Ignore trailing spaces. - Start counting characters of the last word. - Stop when a space appears after counting begins. 💡 Key Concepts Practiced: - String traversal - "charAt()" usage - Reverse iteration - Conditional logic ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) ✅ Key Takeaway: Sometimes solving a problem becomes easier when we traverse the data from the end instead of the beginning. #100DaysOfCode #LeetCode #Java #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 94 - LeetCode Journey Solved LeetCode 35: Search Insert Position in Java ✅ Classic Binary Search problem that tests your fundamentals. Instead of just finding the element, the twist is to return the correct insert position if it’s not present. The key idea is simple: keep narrowing the search space and finally return low, which represents the right position. Clean logic, high impact 💡 Key takeaways: • Strong grip on Binary Search fundamentals • Understanding search space boundaries • Returning correct insertion index • Writing efficient O(log n) solutions ✅ All test cases passed ⚡ O(log n) time and O(1) space Mastering basics like Binary Search is what builds real problem-solving strength 🔥 #LeetCode #DSA #Java #BinarySearch #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 58/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 278. First Bad Version Used binary search on answer space to efficiently find the first bad version while minimizing API calls. ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) Strengthening understanding of binary search optimization and decision-based problems. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
I almost overcomplicated this problem… until I realized it was just prefix sum. 👉 Equal Sum Grid Partition (LeetCode 3546) At first, I thought: “Try all possible cuts.” But that quickly gets messy. Then the real insight hit: If the total sum is even, we just need to find a prefix (row-wise or column-wise) equal to total / 2. That’s it. No brute force. Just clarity. 💡 Lesson: The problem is not about splitting the grid — it’s about finding the right prefix. Time: O(m × n) Space: O(n) Sharing the clean Java solution on GitHub 👇 #leetcode #dsa #java #coding #developers #softwareengineer #codewithishwar
To view or add a comment, sign in
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Try to use the two pointer approach instead of brute force...!try to optimize it with some concrete approach