I am trying to work thru the solution for
https://leetcode.com/explore/learn/card/fun-with-arrays/525/inserting-items-into-an-array/3253/

I have been unable to successfully code the solution. can someone let me know what am I doing wrong ?

nums1 = [1,2,3,0,0,0]
nums2 = [2,5,6]

def merge_sorted_arrays(A1,A2):
    p1 = 2
    p2 = 2
    p0 = p1 + p2 + 1
    while p0 > 0:
        if A2[p2] > A1[p1]:
            A1[p0] = A2[p2]
            p2 -= 1
        else:
            A1[p0] = A2[p2]
            p1 -= 1
        p0 -= 1
    return A1

print(merge_sorted_arrays(nums1, nums2))
$ [1, 2, 2, 2, 5, 6]
Comments (2)