The free, open companion to the Grokking the Coding Interview course by DesignGurus.io, created by Arslan Ahmad.
Stop memorizing solutions. Learn the 41 patterns behind them, and a problem you have never seen starts to look familiar.
This repository is the free index, summary, and cheat sheet collection for that method. The full course adds worked solutions in six languages, runnable tests, and more than 300 hand-picked problems.
- What is "Grokking the Coding Interview"?
- Is there a PDF or book?
- How to use this repo
- How to attack a problem you have never seen
- The patterns
- The problem index
- Cheat sheets
- Glossary
- Recommended reading
- What is coming next
- Contributing
"Grok" means to understand something so completely that it becomes intuitive.
Grokking the Coding Interview is the pattern-based approach to coding interviews. Instead of grinding hundreds of problems and hoping the right ones come up, you learn a small set of reusable techniques. The sliding window, the monotonic stack, the topological sort. Then you learn what each one looks like from the outside. Then a new problem is not new. It is a sliding window problem with a frequency map, and you have written that before.
There are 41 of these patterns, and they cover the overwhelming majority of what gets asked. This methodology was created by Arslan Ahmad. The original, fully updated course lives at DesignGurus.io.
The part people skip is recognition. Knowing how a sliding window works is easy. Knowing that the problem in front of you is a sliding window problem is the skill that gets tested, and it is what this repo is organized around. Every pattern page leads with a Recognize it when section.
No. There is no official PDF, ebook, or printed book of the Grokking the Coding Interview course, and there never has been. The PDF files that circulate online are unofficial copies of an old version. They are missing the newer patterns, the newer problems, and every correction made since they were made.
This repository is the official free way to read the material. Every pattern guide and cheat sheet here is free in your browser, with no account needed. The full, current course, with runnable solutions in six languages, is online at Grokking the Coding Interview.
For more on the series, see What is the Grokking series?
- Read how to recognize the pattern once, so you have a routine for the first sixty seconds of any problem.
- Work through the patterns in order. For each one, read "Recognize it when" first, then the mechanism.
- Practice with the problem index, which maps every problem in the course to its pattern. Cover the pattern heading, name the pattern yourself, then check.
- After every problem, write down which pattern it was and which cue told you. That note is worth more than the solution.
- The night before an interview, reread only the "Recognize it when" sections.
- Go deeper in the full course when you want worked solutions and a place to run them.
A repeatable order beats improvising, and most of it happens before you write any code.
- Restate the problem in one sentence, and confirm it with the interviewer.
- Ask about the input. Sorted? Duplicates? Empty? Negative numbers? How large?
- Read the constraints, and say out loud what complexity they allow. n up to 10^5 rules out O(n²).
- State the brute force. Say what it costs. This is never wasted, and it proves you understood the question.
- Name the pattern. "The window has to grow and shrink, so this is a sliding window with a frequency map."
- Walk one example by hand before coding, so the invariant is settled.
- Write it, saying what each part does as you go.
- Test it out loud on the empty case, the one-element case, and the case that broke your first idea.
- State the final complexity, in time and space, without being asked.
The full breakdown lives in how to recognize the pattern.
All 41, one page each, are in patterns/. The most common twelve:
| Pattern | Recognize it when | Cost |
|---|---|---|
| Two Pointers | Sorted input, looking for a pair or triplet, or an in-place rewrite | O(n) |
| Sliding Window | A contiguous subarray or substring, longest or shortest | O(n) |
| Fast and Slow Pointers | Linked list, cycle or middle, no extra memory | O(n) |
| Merge Intervals | Ranges that may overlap: meetings, bookings, time slots | O(n log n) |
| Hash Maps | Seen before, how many times, or grouped by a computed key | O(n) |
| Monotonic Stack | Next or previous greater or smaller element | O(n) |
| Tree Level Order Traversal | An answer per level, or the shallowest match | O(n) |
| Tree Depth First Search | An answer per path, or ancestor to descendant | O(n) |
| Graphs | Nodes and edges, reachability, fewest hops | O(V + E) |
| Modified Binary Search | Sorted, rotated, or a search over the answer itself | O(log n) |
| Top K Elements | Top K, Kth largest, or K most frequent | O(n log k) |
| Backtracking | Build a configuration, undo it, prune what cannot work | Exponential |
See the full catalog, including the eleven advanced patterns: patterns/README.md
Every problem in the course, 302 of them, mapped to the pattern that solves it, with the difficulty the course assigns: problems/README.md
22 of them have a walkthrough: the problem in our own words, the argument for why it belongs to its pattern, the approach and its invariant, the complexity, and the edge cases to say out loud. They stop short of the code, because writing the code is the part you need to practice.
Plus fourteen more, all linked from the index.
Ten of them, indexed in cheat-sheets/README.md.
Read before an interview:
- How to recognize the pattern in sixty seconds, the constraint table, the trait lookup, the decision tree, and the patterns that get confused with each other.
- All 41 patterns, on one page, the night-before revision sheet, one card per pattern.
- How to talk through a coding interview, the order that works and the sentences that carry weight.
Read while you prepare:
- What complexity passes, reading the intended solution out of the constraints.
- Complexity cheat sheet, every pattern, structure, and algorithm with what it costs.
- BFS vs DFS, and why the wrong one still runs.
- DP vs greedy vs backtracking, the choice that decides most interviews.
- Python vs Java vs JavaScript idioms, the same twenty operations in three languages, plus the traps each one sets.
- Edge cases checklist, by input type.
- Flashcards, 103 cards.
Amortized, invariant, subsequence versus substring, pseudo-polynomial, and the rest: glossary.md
Free guides on the DesignGurus blog and answers, plus every related course: resources.md
Start with the coding patterns, explained and do not just grind LeetCode.
This repo is being built in the open. Planned, in order:
- problems/, more walkthroughs. The index is complete, and 22 of the 302 problems have a page so far.
- templates/, the code skeleton for every pattern in Python, Java, and JavaScript.
- roadmaps/, study plans for one week, four weeks, from scratch, and for experienced engineers who have not interviewed in years.
- cheat-sheets/, more comparisons: sorting algorithms, heap versus ordered set, recursion to iteration, bit tricks, and an annotated mock interview.
Want one of them sooner, or want to write one? Open an issue or a pull request.
This repo explains the patterns and how to recognize them. The course teaches each one in depth, with more than 300 problems, worked solutions in six languages, and an editor to run them in.
- Course: Grokking the Coding Interview
- If the data structures themselves are the gap: Grokking Data Structures
- If dynamic programming is the gap: Grokking Dynamic Programming
- Practice live: Mock interviews with ex-FAANG engineers
- Designing systems, not just solving problems: grokking-system-design
Coding and system design interview tips, straight to your inbox.
Contributions are welcome. See CONTRIBUTING.md. If this repo helps you, please star it so more engineers can find it.
Content is licensed under Creative Commons Attribution 4.0 (CC BY 4.0). The code snippets are additionally under the MIT License, so you can paste them anywhere. You may share and adapt with attribution.
Maintained by DesignGurus.io, the home of the original Grokking the Coding Interview course by Arslan Ahmad.