Algorithm · Apple · Medium
1. Merge two sorted arrays Use two pointers, one for A and one for B, both starting at index 0. At each step compare the current elements: If A[i] <= B[j], append A[i] to the result and increment i. Otherwise append B[j] and increment j. When one array is fully consumed, append every remaining element from the other array. This works because both inputs are already sorted. The result is built in non-decreasing order by repeatedly taking the smaller available front element.…
Checking your access…