Arrays & Strings
The six foundational patterns — Two Pointers, Sliding Window, Prefix Sums, Binary Search, Hashing, Intervals & Greedy.
1 min readInterview · DSA Patterns
These six patterns unlock roughly 40% of interview problems on their own. They share a common shape: an array or string, an O(n) or O(n log n) target complexity, and an invariant maintained as we sweep.
Learn them first.
Two Pointers
Sorted array, pair with property, palindrome check, partition in place
Sliding Window
Longest/shortest/max-sum subarray with a constraint
Prefix Sums & Difference Arrays
Range queries in O(1) (prefix sum); range updates in O(1) (difference array)
Binary Search
Sorted array, first-true predicate, or binary-search-on-answer
Hashing
O(1) lookup, frequency counts, group-by
Intervals & Greedy
Sort by custom key, then sweep
Finished reading?
Mark it done to track your progress in Interview.