← Two Pointers

Pattern Recognition Drill

#6 — Merge two sorted arrays

Easy Arrays & Strings

The Problem

Given sorted arrays a and b, return a single merged sorted array.

What approach would you use?

Think about it before scrolling down.

Key Signals

Two Pointers

One pointer per array. Always pick the smaller front element. O(n+m) time.

Alt: Sorting

Concatenate and sort: O((n+m) log(n+m)). Works but ignores that inputs are already sorted.

Common Trap

Don't re-sort — the merge step is the whole point. Interviewers test if you exploit sorted order.

← #5 #7 →