Arrays & Hashing problems, grouped by pattern

Most interview problems start with an array. The patterns here teach you to avoid the nested loop: keep a running total, move two pointers toward each other, or slide a window across the input so every element is visited once.

When to reach for it

  • The input is a list and the brute force is O(n²) or worse
  • The question asks about a contiguous subarray or substring
  • The array is sorted, or sorting it would not break the answer

Mistakes to watch for

  • Shrinking a variable window too late or too early
  • Forgetting the empty prefix (sum 0 seen once) in prefix-sum counting
  • Off-by-one errors when the window size is fixed

The 195 problems

1Two Sum

2Moore's Voting Algorithm

4Double Reversal Trick

7In-place Transformations

8Merge Sort Like Approach

9Dutch National Flag

16Elimination Recurrence

24Fenwick Tree (BIT)

26Sorting