Given sorted arrays nums1 (with m real elements + n zeros) and nums2 (n elements), merge them in-place into nums1 in non-decreasing order.
nums1=[1,2,3,0,0,0] m=3, nums2=[2,5,6] n=3[1,2,2,3,5,6]Merging from the front would overwrite unseen nums1 elements. By starting at the end of nums1 (where the zeros are), we fill the largest slot first. The write pointer p always lands in the "used-up" region — we can never clobber an unread value.