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
2Moore's Voting Algorithm
- Majority Element Animated Easy
- Majority Element II Animated Medium
3Kadane's Algorithm
- Kadane's Algorithm - Simple Animated Medium
- Find minimum subarray sum Animated Medium
- Kadane's Algo - Circular Array - No Extra Space Animated Hard
4Double Reversal Trick
- Rotate Array Animated Medium
- Reverse Words in a String Animated Medium
5Two Pointer
- Two Sum II - Input Array Is Sorted Animated Medium
- Valid Triangle Number Animated Medium
6Right to Left Traversal
- Array Leaders Animated Easy
- Product of Array Except Self Animated Medium
7In-place Transformations
- Set Matrix Zeroes Animated Medium
- Find All Duplicates in an Array Animated Medium
8Merge Sort Like Approach
- Count Inversions Animated Medium
- Arranging the array Animated Medium
9Dutch National Flag
- Sort Colors Animated Medium
10Prefix Sum Strategy
- Subarray Sum Equals K Animated Medium
- Subarray with given XOR Animated Medium
- Range Sum Query - Immutable Animated Easy
11Sliding Window · Fixed
- Maximum Average Subarray I Animated Easy
- K Radius Subarray Averages Animated Medium
- Maximum Number of Vowels in a Substring of Given Length Animated Medium
12Sliding Window · Variable
- Minimum Size Subarray Sum Animated Medium
- Count of Subarrays with Product Less Than K Animated Medium
13Sliding Window · Hash Map
- Number of Substrings Containing All Three Characters Animated Medium
- Minimum Window Substring Animated Hard