DSA with Python.
Data structures and algorithms in Python — Pythonic solutions, complexity analysis, and LeetCode-style problem sets.
Beginner
Start here — no prior experience needed
Python Data Structures and Their Real Costs
Which structure to reach for and what each operation actually costs — measured, including the four Python-specific traps that turn a linear solution quadratic.
Arrays and Two Pointers
Opposite ends, same direction, and fast-slow — three variants that turn a nested loop into one pass, each with the invariant that proves it correct.
Hashing and Counting
The canonical-key trick, prefix sums in a dict, and the two questions that turn an O(n²) scan into one pass — plus what Python can and cannot use as a key.
Sliding Window
Fixed and variable windows, the amortised argument that makes a nested-looking loop O(n), and the condition that decides whether a window works at all.
Stacks, Queues, and the Monotonic Stack
Matching, undoing, and the monotonic stack that answers 'next greater element' in one pass — with the amortised argument and the histogram problem it unlocks.
Intermediate
For developers with core concepts down
Linked Lists and Trees
Pointer reversal without losing the list, the four traversals and when each is the right one, and the recursion depth that turns a correct solution into a crash.
Graphs: BFS, DFS, and Topological Order
Why BFS and not DFS for shortest path, cycle detection that distinguishes directed from undirected, and the two topological sorts — with the grid problems that are graphs in disguise.
Sorting, Binary Search, and Heaps
Stability and custom keys, binary search on an answer space with nothing sorted, and the crossover where a heap stops beating a sort.
Advanced
Production-grade patterns for experienced engineers
Dynamic Programming
Finding the recurrence, converting recursion to memoisation to a bottom-up loop, and the space reduction that turns O(n·m) into O(m) — each step measured.
Backtracking
One template for subsets, permutations and N-queens — the copy that everyone forgets, and pruning measured as the nodes it never visits.