DSA tutorials
277 articles · page 4 of 14Hand-written tutorials, ordered as a recommended learning path.
- 61 Redundant Parentheses Learn to detect redundant parentheses in expressions using a stack. Covers the algorithm, Python implementation, and edge cases with traces.
- 62 Binary Search A practical guide to binary search — the classic template, off-by-one traps, Python's bisect module, and the binary-search-on-answer pattern, with six worked problems.
- 63 Decode String Decode nested encoded strings like '3[a2[c]]' using a stack. Complete walkthrough with Python solution, traces, and edge cases.
- 64 Greedy An introduction to greedy algorithms — when the locally best choice gives a globally optimal answer, when it doesn't, the exchange argument, and six classic problems.
- 65 Largest Rectangle Histogram Find the largest rectangle in a histogram using a monotonic stack in O(n). Detailed walkthrough, Python code, visual trace, and common pitfalls.
- 66 Maximal Rectangle Find the maximal rectangle containing only 1s in a binary matrix. Builds on the largest rectangle in histogram technique with detailed explanation.
- 67 Asteroid Collision Solve the asteroid collision problem (LeetCode 735) using a stack. Covers collision rules, Python implementation, and all edge cases.
- 68 Remove K Digits Use a monotonic stack to remove k digits from a number to make it as small as possible. LeetCode 402 solution with Python code and traces.
- 69 Online Stock Span Design an Online Stock Span class (LeetCode 901) using a stack. Covers amortized analysis, Python implementation, and the price-span pair technique.
- 70 BFS with Queues Master BFS using queues for tree level-order traversal and shortest path in unweighted graphs. Python implementations with detailed traces.
- 71 Binary Search Patterns Master binary search with three templates -- exact match, first/last true, and answer space search. Covers rotated arrays, peak elements, and common off-by-one mistakes.
- 72 Sliding Window Max (Deque) Solve the sliding window maximum problem in O(n) using a monotonic deque. Covers the algorithm, Python code, visual traces, and variations.
- 73 First Non-Repeating Stream Find the first non-repeating character in a character stream using a queue and hash map. Python solution with O(1) amortized per query.
- 74 Rotten Oranges Solve the Rotten Oranges problem (LeetCode 994) using multi-source BFS. Covers the simultaneous spread pattern, Python code, and grid BFS template.
- 75 Task Scheduler Solve the Task Scheduler problem (LeetCode 621) using a queue and max-heap. Covers the greedy formula and simulation approaches with Python code.
- 76 Walls and Gates Fill each empty room with the distance to its nearest gate using multi-source BFS. LeetCode 286 solution with Python code and grid BFS template.
- 77 Design Hit Counter Design a hit counter that counts hits in the past 5 minutes using a queue. LeetCode 362 solution with O(1) amortized operations.
- 78 Moving Average Stream Calculate the moving average from a data stream using a queue with fixed window size. LeetCode 346 solution with O(1) per operation.
- 79 Shortest Path Binary Matrix Find the shortest path in a binary matrix using BFS with 8-directional movement. LeetCode 1091 solution with Python code and grid traversal tips.
- 80 Jump Game BFS Solve Jump Game III (LeetCode 1306) and Jump Game IV (LeetCode 1345) using BFS. Covers graph modeling of array problems with queue-based traversal.