Algorithms Practice: Patterns for the Coding Round
Many data engineering loops include one classic algorithms round. These problems are grouped by pattern, because recognising the pattern is most of the work. Learn the templates first in Algorithm patterns, then solve a pattern’s problems back to back until the template is automatic.
Every problem runs in your browser: write the function, press Run tests to see each test’s result next to the expected value, and press Debug to step through your code line by line.
Sliding Window
| # | Problem | Difficulty |
|---|---|---|
| 01 | Longest Substring Without Repeating Characters | medium |
| 02 | Minimum Window Containing All Required Characters | hard |
| 03 | Shortest Burst Reaching a Throughput Target | medium |
| 04 | Longest Uniform Run With at Most k Replacements | medium |
| 05 | Find All Anagram Positions | medium |
Two Pointers (Opposite Ends)
| # | Problem | Difficulty |
|---|---|---|
| 06 | Two Sum: Unsorted (Hash Map) and Sorted (Two Pointers) | easy |
| 07 | 3Sum: All Unique Triplets Summing to Zero | medium |
| 08 | Container With the Most Water | medium |
| 09 | Valid Palindrome After Normalisation (and With One Deletion) | easy |
Two Pointers (Same Direction)
| # | Problem | Difficulty |
|---|---|---|
| 10 | Compact a Sorted Array In Place (Keep at Most k Copies) | easy |
| 11 | Move Zeroes and Remove Element (Stable Partition) | easy |
Fast & Slow Pointers (Floyd’s Cycle Detection)
| # | Problem | Difficulty |
|---|---|---|
| 12 | Detect a Cycle and Find Where It Starts | medium |
| 13 | Happy Number (Cycle Detection on a Function) | easy |
| 14 | Find the Duplicate Number Without Modifying the Array | medium |
| 15 | Palindrome Linked List in O(1) Space | easy |
Prefix Sum
| # | Problem | Difficulty |
|---|---|---|
| 16 | Range Sum Queries in 1D and 2D (Precompute Once, Answer in O(1)) | medium |
| 17 | Subarray Sum Divisible by k (Prefix Sums + Remainders) | medium |
| 18 | Balance Point of a Partition (Pivot Index) | easy |
Binary Search
Heap (Top-K and Greedy Merging)
| # | Problem | Difficulty |
|---|---|---|
| 23 | Kth Largest Element: Heap vs Quickselect | medium |
| 24 | K Closest Points to the Origin (Nearest Depots) | medium |
| 25 | Cheapest Way to Merge Sorted Files | medium |
Monotonic Stack
| # | Problem | Difficulty |
|---|---|---|
| 26 | Days Until a Warmer Reading (Next Greater Element) | medium |
| 27 | Trapping Rain Water | hard |
| 28 | Largest Rectangle in a Histogram | hard |
| 29 | Smallest Subsequence With Each Letter Once | hard |
Kadane’s Algorithm (Best Subarray)
| # | Problem | Difficulty |
|---|---|---|
| 30 | Maximum Subarray Sum, Including the Circular Case | medium |
| 31 | Maximum Product Subarray | medium |
| 32 | Best Time to Buy and Sell (One Trade and Unlimited Trades) | easy |
Merge Intervals
| # | Problem | Difficulty |
|---|---|---|
| 33 | Insert an Interval Into a Sorted Schedule | medium |
| 34 | Meeting Rooms: Any Conflict? How Many Rooms? | medium |
| 35 | Fewest Removals to Make Intervals Non-Overlapping | medium |
Hashing, Stacks and Bit Tricks (Must-Know Classics)
| # | Problem | Difficulty |
|---|---|---|
| 36 | Find the Missing ID (Sum, XOR and Their Trade-Offs) | easy |
| 37 | Valid Brackets (and the Minimum Fix) | easy |
| 38 | Valid Anagram and Group Anagrams | easy |
| 39 | Roman Numerals: Parse and Format | easy |
Graphs: BFS, DFS and Union-Find
| # | Problem | Difficulty |
|---|---|---|
| 40 | Count Connected Regions in a Grid (Islands) | medium |
| 41 | Shortest Path Through a Grid With Obstacles | medium |
| 42 | Merge Customer Records That Share an Email (Union-Find) | medium |
Dynamic Programming
| # | Problem | Difficulty |
|---|---|---|
| 43 | Fewest Coins and Number of Ways (Unbounded Knapsack) | medium |
| 44 | Edit Distance for Fuzzy Matching | hard |
| 45 | Longest Increasing Subsequence in O(n log n) | medium |
Backtracking and Tries
| # | Problem | Difficulty |
|---|---|---|
| 46 | Subsets and Combination Sum (Backtracking) | medium |
| 47 | Autocomplete With a Trie (Top Suggestions by Frequency) | medium |