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 28 problems

1Two Sum

2Moore's Voting Algorithm

3Kadane's Algorithm

4Double Reversal Trick

5Two Pointer

6Right to Left Traversal

7In-place Transformations

8Merge Sort Like Approach

9Dutch National Flag

10Prefix Sum Strategy

11Sliding Window · Fixed

12Sliding Window · Variable

13Sliding Window · Hash Map