Merging Sorted Arrays in O(1) Space Complexity

🔹 Day 36: Merge Sorted Array (LeetCode #88) 📌 Problem Statement: You are given two sorted arrays, nums1 and nums2, and two integers m and n representing the number of initialized elements in each. Merge nums2 into nums1 as one sorted array in non-decreasing order. ✅ My Approach: I appended all elements of nums2 into the extra space of nums1 and then sorted the combined array. While this is a simple approach, an optimized method could merge from the end to avoid extra sorting. 📊 Complexity: Time Complexity: O((m + n) log(m + n)) Space Complexity: O(1) ⚡ Submission Stats: Runtime: 1 ms (Beats 27.92%) Memory: 42.32 MB 💡 Reflection: This problem reinforces the importance of understanding in-place array manipulation. A clean and straightforward implementation that still gets the job done! 💪 #LeetCode #Java #Arrays #Sorting #100DaysOfCode #Day36

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore content categories