Pattern

Array manipulation

Trade extra passes or a hash-based lookup for the O(n²) brute force that scanning an array naively tempts you into.

What it is

"Array" as a label doesn't name one technique — it names the family of questions where the input is a flat, unordered (or arbitrarily ordered) list of numbers and the challenge is entirely about how you look at it: once, twice, forward, backward, with or without an auxiliary hash set. Under this label you'll find hashing for O(1) membership checks, running-sum tricks (Kadane's algorithm, prefix/suffix products), and index-as-hash-slot tricks that get you O(1) space when values are bounded. What ties them together is the absence of any other structure (no order, no tree, no graph) to lean on, so the array itself, and how many times you're willing to walk it, is the whole design space.

When it applies

Tells in the problem

The classic mistake

The recurring failure is reaching immediately for the nested-loop, compare-everything-against-everything solution because it's the first thing that comes to mind for "find a pair" or "find a duplicate," and then not stepping back to ask what a single well-chosen pass with a hash set or a running value could replace it with. This happens because the brute force is easy to state correctly, so it feels safe to start typing it — but on the array sizes these questions specify (often in the hundreds of thousands), it's the wrong complexity from the start. Notice the trap by asking, before writing any loop, "am I about to re-scan the array from inside a scan of the array" — if yes, look for what a set, a counter, or a running total from the first pass would tell you instead.

Questions to start with

All 12 array manipulation questions

Problem statement, examples and hints are free on every page; the worked approach, solution and tests are in the company guides.

Free starter pack

13 must-tier questions with full solutions

Sign in with an email — no purchase — and read them in the full reader.

No password, no spam. One sign-in email; you can read the pack in the full reader.