Let's trace nums1 = [4,5,6,0,0,0], m = 3, nums2 = [1,2,3], n = 3.
Pointers: p1 = 2 (val ), p2 = 2 (val ), write = 5.
: place at index . p1 = 1, write = 4.
: place at index . p1 = 0, write = 3.
: place at index . p1 = -1, write = 2.
p1 exhausted. Copy remaining nums2: place at indices .
Result: [1,2,3,4,5,6].
You visit each element once. That's time, space since everything is done in-place.