DSA tutorials
277 articles · page 12 of 14Hand-written tutorials, ordered as a recommended learning path.
- 221 KMP Algorithm Master the Knuth-Morris-Pratt algorithm — build the failure function, avoid redundant comparisons, and solve pattern matching problems in O(n + m) time.
- 222 Monotonic Stack Learn the monotonic stack technique — next greater element, stock span, largest rectangle, and trapping rain water solved with clean Python templates.
- 223 Segment Trees Master segment trees for range queries and updates. Covers build, query, update, lazy propagation, and applications for range sum, min, and max problems.
- 224 Trie Complete guide to the Trie data structure. Covers insertion, search, prefix matching, deletion, and real-world applications like autocomplete and word puzzles.
- 225 Median Stream Solve Find Median from Data Stream with two heaps. Learn the balance invariant, why it gives O(log n) inserts and O(1) median, and the common pitfalls.
- 226 Jump Game Solve Jump Game with a single-pass greedy max-reach approach. Compare it against the dynamic programming solution and learn when greedy is provably optimal.
- 227 Meeting Rooms II Solve Meeting Rooms II two ways: a min-heap of end times and a sweep-line over start and end events. Learn when each shines and how to pick in interviews.
- 228 Merge Intervals Walk through Merge Intervals step by step. Brute force vs the optimal sort-and-sweep approach, edge cases, and clean code you can ship in an interview.
- 229 Rotate Array Rotate an array by k steps in O(1) extra space using the triple-reverse trick. Compare it with the extra-array approach and learn why this pattern keeps showing up.
- 230 Backtracking A practical guide to backtracking: the recursion template, pruning, classic problems with code, and complexity analysis for subsets and permutations.
- 231 Bellman-Ford Understand Bellman-Ford's relaxation loop, how it handles negative edges, detects negative cycles, and why it costs more than Dijkstra.
- 232 Dijkstra Learn Dijkstra's shortest path algorithm with a clean Python implementation, complexity analysis, and the priority queue intuition behind it.
- 233 Divide & Conquer Learn the divide-and-conquer pattern through merge sort and quick sort, recurrence relations, the Master theorem, and how to recognize the pattern.
- 234 Fenwick Tree Implement and understand the Fenwick tree, also called the binary indexed tree, for O(log n) prefix sums and point updates in just a few lines.
- 235 Heaps Learn how heaps power priority queues, why heapq runs push and pop in O(log n), and how to solve classic Top-K and merge problems in Python.
- 236 MST: Kruskal & Prim Build minimum spanning trees with Kruskal's union-find approach and Prim's priority queue approach, with side-by-side Python implementations.
- 237 3Sum A careful walkthrough of 3Sum using sort plus two pointers. We handle duplicate triplets cleanly and avoid the classic off-by-one traps.
- 238 Buy Sell Stock Walk through Best Time to Buy and Sell Stock. We go from the quadratic brute force to a clean one-pass solution tracking the running minimum.
- 239 Climbing Stairs Walk through Climbing Stairs from brute force recursion to bottom-up DP, with edge cases, complexity analysis, and an interview script.
- 240 Coin Change Walk through Coin Change with brute force recursion, memoization, and bottom-up DP. Includes complexity analysis and interview script.