Two Heads for Two Arrays
Each pointer walks a different array. A first while advances both while they are valid and decides what to take; two trailing while loops drain whichever array still has leftovers. This 3-loop template handles merges and comparisons cleanly, and the fill direction (forward or backward) is chosen to avoid clobbering data still being read.
Three While Loops
88. Merge Sorted Array
1768. Merge Strings Alternately
Easy·
Solutions:
FIG. 1768 MERGE STRINGS ALTERNATELY● INTERACTIVE