Dinesh Kolhe’s Post

🚀 Day 74 of #100DaysOfCode Today’s challenge was a clean and efficient array problem — LeetCode: Merge Sorted Array ✅ 📌 Problem Summary You’re given two sorted arrays, where the first array has extra space at the end. The task is to merge the second array into the first in-place, keeping everything sorted. 🧠 My Approach Instead of shifting elements forward (which is costly), I used a reverse two-pointer technique: Start comparing elements from the end of both arrays Place the larger element at the last available position Move pointers accordingly until all elements are merged This avoids extra space and keeps the solution optimal. ⚙️ Complexity ⏱ Time: O(m + n) 💾 Space: O(1) (in-place merge) 🔥 Key Learning Working from the back can simplify in-place array problems Two-pointer strategies are incredibly powerful for sorted data Another day, another solid problem solved 💪 Onward to Day 75 🚀 #100DaysOfCode #LeetCode #Java #DSA #ProblemSolving #CodingJourney

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories