How to use this guide
Go top to bottom, one topic at a time. Each level builds on the one before. A single 45-minute session looks like this:
- Read (10 min)"In simple words", the analogy, and the key ideas for today's topic.
- Type the template (5 min)Close the page and write the Java code from memory. Compare.
- Solve one problem (25 min)Start with the Easy ones, then Medium. Stuck for 20 minutes? Read a solution, then re-solve it tomorrow without help.
- Note it (5 min)Write one line: the pattern you used and the mistake you made.
Tick Mark done once you've solved 3–5 problems from a topic. Your ticks are saved in this browser only.
Solving a problem in the interview
- UnderstandRepeat the problem in your words. Ask about input size, value ranges, duplicates, empty input.
- ExamplesWalk through the given example and add one edge case of your own.
- Brute forceSay the simple solution and its complexity, even if it's slow.
- OptimizeFind the bottleneck and name the pattern ("this is a sliding window").
- CodeClear names, small helper methods, talk while you type.
- TestDry-run your code on the example, then on the edge cases.
- ComplexityFinish with time and space, without being asked.
Pattern finder
Read the problem, find the clue on the left, try the technique on the right.
| If the problem says… | Try |
|---|
Complexity at a glance
| Structure | Access | Search | Insert | Delete | Space |
|---|---|---|---|---|---|
| Array | O(1) | O(n) | O(n) | O(n) | O(n) |
| ArrayList (at end) | O(1) | O(n) | O(1)* | O(1) | O(n) |
| Linked list (at head) | O(n) | O(n) | O(1) | O(1) | O(n) |
| Stack / Queue (ArrayDeque) | top/front O(1) | O(n) | O(1) | O(1) | O(n) |
| HashMap / HashSet | — | O(1) avg | O(1) avg | O(1) avg | O(n) |
| TreeMap / balanced BST | O(log n) | O(log n) | O(log n) | O(log n) | O(n) |
| Binary heap (PriorityQueue) | top O(1) | O(n) | O(log n) | top O(log n) | O(n) |
| Trie | — | O(L) | O(L) | O(L) | O(chars × alphabet) |
| Union-Find | — | find ≈ O(1) | union ≈ O(1) | — | O(n) |
| Segment / Fenwick tree | — | range O(log n) | update O(log n) | — | O(n) |
* amortized · L = word length
Edge cases to test every time
- Empty input, one element, two elements
- All elements equal; many duplicates
- Negative numbers and zero
- Very large values →
intoverflow, uselong - Already sorted and reverse sorted input
nullhead / root; single-node tree; skewed tree- Disconnected graph; graph with a cycle; self-loops
- Target not present; answer at the first or last index
Where to practise
- LeetCode — every problem in this guide links there
- NeetCode 150 — curated list grouped by pattern
- GeeksforGeeks — theory and company-wise questions
- VisuAlgo — animations of sorting, trees and graphs
Problem difficulty: E Easy M Medium H Hard