Pattern 1 · 10 problems

Array & Traversal

Concepts: Linear scan, prefix/suffix, simulation.

Signal: One pass over an array, running min/max, or left×right products.

Concept walkthrough
best = init; state = init
for x in nums:
  update state with x
  best = improve(best, state)
return best

What this pattern is

Most interview problems start as an array scan. Master a clean left-to-right pass, then layer prefix/suffix products, running minima, and in-place swaps. Before any fancy pattern, ask: “Can one linear pass with O(1) or O(n) extra memory solve this?”

When do I use this?

  • ✓ Need a single answer from scanning once or twice
  • ✓ Prefix / suffix products or running sums
  • ✓ In-place rearrange (move zeroes, rotate)
  • ✓ Kadane-style contiguous optimum

Interview template

Memorize the shape, not a specific problem.

best = init; state = init
for x in nums:
  update state with x
  best = improve(best, state)
return best

Practice problems