Merge Sorted Array with In-Place Insertion Approach

Day 7 🚀 of the #100DaysOfLeetCode challenge Problem 88: Merge Sorted Array Today’s focus was on in-place merging using the insertion and shifting approach. Instead of using an extra array, I compared elements from nums1 and nums2. Whenever an element from nums2 was smaller, I shifted the remaining elements in nums1 to the right and inserted it at the correct position. After each insertion, I updated the effective size of nums1 and continued the process until all elements were merged. This approach helped me clearly understand: -->How in-place array manipulation works -->Why boundary management (m and n) is critical -->How shifting impacts time complexity Time Complexity: O(m × n) in worst case due to shifting Space Complexity: O(1) (no extra space used) Even though there’s a more optimal two-pointer solution from the back (O(m + n)), practicing this method strengthened my fundamentals in array handling and index control. Every problem teaches something beyond just passing test cases. Consistency > Intensity. #LeetCode #Java #DataStructures #ProblemSolving #CodingJourney #100DaysOfCode

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories