Coding Interview Cheat Sheets
Pattern recognition cards, complexity quick-reference, and study guides — all in one place.
321
Problems
21
Patterns
12
Cheat cards
Pattern Recognition Cards
Use these when you are unsure which pattern fits a problem.
Sliding Window
Practice →Maintain a contiguous sub-sequence and expand/shrink from one end.
- ✓ Longest/shortest subarray with a constraint
- ✓ Substring problems with a frequency limit
- ✓ Fixed-size window max/min/sum
O(n) time · O(1)–O(k) space
Two Pointers
Practice →Use two indices to reduce an O(n²) search to O(n) on sorted or structured data.
- ✓ Sorted array: pair sum, 3Sum, container
- ✓ In-place modification (remove dups, move zeros)
- ✓ Slow/fast for cycles or middle of list
O(n) time · O(1) space
Binary Search
Practice →Halve the search space each step — works on any monotonic condition, not just arrays.
- ✓ Sorted array or rotated sorted array
- ✓ "Minimum X such that condition holds"
- ✓ Search in 2D sorted matrix
O(log n) time · O(1) space
Prefix Sum
Practice →Precompute running sums to answer range sum queries in O(1).
- ✓ Range sum queries (immutable array)
- ✓ Subarray sum equals k
- ✓ Count of subarrays divisible by k
O(n) build · O(1) query
Hash Map
Practice →Trade space for O(1) average lookup to turn O(n²) problems into O(n).
- ✓ Two-sum variants
- ✓ Frequency counting / grouping
- ✓ First/last occurrence
O(n) time · O(n) space
Stack
Practice →LIFO structure for matching, undoing, or finding the next greater/smaller element.
- ✓ Matching brackets / nesting
- ✓ Next greater element (monotonic stack)
- ✓ Expression evaluation
O(n) amortized · O(n) space
BFS / Queue
Practice →Level-order traversal; guarantees shortest path in unweighted graphs.
- ✓ Shortest path (unweighted)
- ✓ Level-by-level tree traversal
- ✓ Multi-source spread (rotting oranges)
O(V + E) time · O(V) space
Heap / Priority Queue
Practice →Always access the min or max in O(log n); ideal for k-th element and scheduling.
- ✓ Kth largest/smallest element
- ✓ Merge k sorted lists/streams
- ✓ Task scheduling / rearrangement
O(n log k) time · O(k) space
Dynamic Programming
Practice →Break into overlapping sub-problems. Define state → recurrence → base case → optimise.
- ✓ Optimal value (min cost, max profit)
- ✓ Count of ways
- ✓ "Can we achieve X?" yes/no
O(n²) typical · O(n)–O(n²) space
DFS / Backtracking
Practice →Explore all paths; prune branches that can never lead to a valid solution.
- ✓ All subsets / permutations / combinations
- ✓ Word search in a grid
- ✓ N-queens, Sudoku
O(2ⁿ) or O(n!) · O(n) recursion stack
Union-Find
Practice →Near-O(1) union and find for dynamic connectivity problems.
- ✓ Connected components (dynamic)
- ✓ Cycle detection (undirected)
- ✓ Merging groups (accounts merge)
O(α(n)) per op · O(n) space
Topological Sort
Practice →Linear ordering of vertices in a DAG — detect cycles and find dependency order.
- ✓ Course scheduling / prerequisites
- ✓ Build order / dependency resolution
- ✓ Detect cycles in directed graph
O(V + E) time · O(V) space
Time Complexity Quick Reference
Interview target for n = 10⁶: aim for O(n log n) or better.
| Complexity | Type |
|---|---|
| O(1) | Constant |
| O(log n) | Logarithmic |
| O(n) | Linear |
| O(n log n) | Log-linear |
| O(n²) | Quadratic |
| O(2ⁿ) | Exponential |
| O(n!) | Factorial |
Pattern Decision Tree
When you see these keywords in a problem, reach for the corresponding pattern.
| Keyword / constraint | Pattern to try first |
|---|---|
| Longest / smallest subarray with constraint | Sliding Window |
| Sorted array, pair sum, in-place removal | Two Pointers |
| "Minimum X satisfying condition" with large range | Binary Search on Answer |
| Range sum query, subarray sum = k | Prefix Sum + Hash Map |
| Shortest path, minimum steps, level-by-level | BFS |
| All paths, all subsets/permutations, Sudoku | DFS / Backtracking |
| Kth largest, merge k sorted, task schedule | Heap |
| Max/min value with sub-problems, count of ways | Dynamic Programming |
| Prerequisites, dependency order, build system | Topological Sort |
| Brackets matching, next greater element | Monotonic Stack |
| Connected groups, dynamic connectivity | Union-Find |
| Prefix matching, autocomplete, word dictionary | Trie |
Featured Architecture & Interview Deep Dives
System Design Cheat Sheet: Latency & Math Guide
Latency numbers every engineer should know, back-of-the-envelope capacity estimations, database selection matrices, and printable 1-page layout.
LLD vs HLD: Low-Level vs High-Level Design Compared
Key differences side-by-side, interview round expectations, design patterns vs distributed architectures, and concrete interview examples.
Amazon Leadership Principles: 60+ Real Interview Questions
All 16 Amazon LPs covered with real interview questions, STAR method model answers, Bar Raiser scoring secrets, and the 6-story prep matrix.
10 Best AI Code Review Tools in 2026: Tested & Ranked
Benchmarked comparison of CodeRabbit, Copilot, Qodo, Snyk, and PR-Agent across review speed, noise suppression, and AST analysis.
Top 30 GitHub Resource Collections (CS Core & Placements)
Curated free repositories for full CS degree curriculums, campus placements, university lecture slides, Linux kernel source code, and low-level system design.
📁 computer-science
A complete free CS degree curriculum with ordered courses
📁 Complete-Placement-Preparation
DSA, CS core, aptitude and HR preparation for Indian placements
📁 Interview-Prepartion-Data-Structures-Algorithms-CS-Core
CS core subject questions organised by topic
📁 coding-interview-university
A multi-month CS study plan covering OS, networks and databases
📁 tech-interview-handbook
Interview process, algorithms, behavioural and resume guidance
📁 awesome-interview-questions
Interview questions indexed by subject and technology
📁 free-programming-books
Thousands of free books and courses including all four CS core subjects
📁 cs-video-courses
Thousands of university CS courses indexed by subject
📁 SemWiseResourcesIIIT
Semester-wise course resources from IIIT Delhi
📁 awesome-cs-courses
University CS courses with assignments and materials
📁 xv6-public
A small teaching operating system you can actually read
📁 awesome-os
Operating system development resources and reading
📁 os-tutorial
Build a minimal operating system from scratch, step by step
📁 awesome-database-learning
Database internals, papers and learning material
📁 sql-style-guide
Readable, consistent SQL conventions
📁 awesome-postgres
PostgreSQL tools, extensions and learning resources
📁 awesome-computer-networking
Networking learning resources, tools and references
📁 build-your-own-x
Build your own OS, database, network stack and shell
📁 awesome-low-level-design
Object-oriented design problems with solutions and diagrams
📁 low-level-design-primer
OOP design problems, patterns and worked solutions
📁 java-design-patterns
Every classic design pattern implemented and explained
📁 Awesome-DSA-Resource
Curated DSA resources; the round that runs alongside CS core
📁 system-design-primer
System design concepts; CS core is its foundation
📁 developer-roadmap
Interactive computer science and subject-specific roadmaps
📁 every-programmer-should-know
Concepts every developer should eventually understand
📁 awesome-cheatsheets
Cheat sheets for languages, tools and concepts
📁 Placement-Preparation-Resources
Indian placement resources across CS core, DSA and aptitude
📁 professional-programming
A large curated reading list for professional practice
📁 papers-we-love
Foundational CS papers by topic
📁 free-for-dev
Free tiers of cloud, database and hosting services
Ready to practice?
Apply these patterns to real problems with difficulty filters and progress tracking.