Merge 2 sorted arrays without using any extra space (O(1) space). Asked in the SP-L1 upgrade interview stage.
Write a function that merges two sorted arrays in place so that the final combined order is sorted. Assume the first array has enough trailing capacity to hold all elements from the second array.
merge_sorted_arrays(nums1, m, nums2, n)
nums1: list of length m + n, where the first m elements are sorted and the remaining slots are placeholdersm: number of valid elements in nums1nums2: sorted list of length nn: number of valid elements in nums2nums1 after mergingdef merge_sorted_arrays(nums1, m, nums2, n):