← All Patterns

Pattern Recognition Drill

#6

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.

Merge two sorted arrays

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 →