🚀 Day 1/30: Kicking off my DSA Journey! Today’s focus: LeetCode 283 – Move Zeroes. 📝 The Challenge Given an integer array nums, the goal is to shift all the 0s to the end while keeping the non-zero elements strictly in their original order. ⚠️ The Catch: This must be done in-place (no extra memory allowed). 📌 Example Input: nums = [0, 1, 0, 3, 12] Output: [1, 3, 12, 0, 0] Explanation: The zeros are pushed to the back, while 1, 3, 12 stay in their exact original sequence. 💡 First Thoughts The brute-force way out? Just create a secondary array, dump the non-zero numbers in first, and pad the rest with zeros. But that directly violates the $O(1)$ space constraint. The real puzzle was figuring out how to achieve this by only modifying the original array. ⚙️ The Solution: Two-Pointer Technique To optimize the solution, I utilized the Two-Pointer method: Pointer i acts as the explorer, traversing the array. Pointer j acts as an anchor, tracking where the next non-zero element belongs. The Steps: Start j at index 0. Loop through the array with i. Whenever i finds a non-zero number, swap it with nums[j] and bump j up by 1. 🧠 Why It Works Because j only steps forward when a non-zero element is securely locked into place, the original relative order is perfectly preserved. As the non-zeroes move to the front, the zeros naturally get pushed to the back. Zero extra data structures, just a single pass! 📊 Complexity Time Complexity: $O(n)$ — We only traverse the array once. Space Complexity: $O(1)$ — Everything is modified completely in-place. 🔑 Takeaways The Two-Pointer strategy is an absolute lifesaver for tricky array manipulations. "In-place modification" and "preserving relative order" are incredibly common technical interview constraints. Small problems are the best way to test and solidify your core fundamentals. Consistency beats motivation! 💪 Let's build these skills one problem at a time. ##30DaysOfCode #DSA #LeetCode #Java #ProblemSolving #InterviewPreparation #CodingJourney
Carry On Adarsh brother
Great start