Home › Learn
Data structures and algorithms, one level at a time
Code the Hero teaches 70 ideas across 10 worlds. Each one is a level you solve by writing real Python, Java or JavaScript, while a pixel hero acts out every line.
1. Array Plains FREE
Scan, swap and sort a row of crates
- The Heaviest Crate: Linear scan, O(n)
- Reverse the Row: Two pointers, n/2 swaps
- Count the Apples: Counting in one pass, O(n)
- Irrigation Channels: Prefix sums: O(n) build, O(1) query
- Rotate the Row: Rotation by three reversals, O(n)
- Bubble Sort Machine: Sorting by adjacent swaps, O(n²)
- Storm Harvester: Kadane's algorithm, O(n)
2. Twin Rivers FREE
Two pointers and sliding windows
- Row to the Pair: Two pointers on sorted data, O(n)
- Palindrome Ferry: Two pointers from both ends, O(n)
- Remove Duplicates: Read pointer and write pointer, O(n)
- The Sliding Net: Sliding window, O(n)
- Stretchy Net: Variable sliding window, O(n)
- Container Dock: Two pointers, greedy O(n)
- The Flood: Trapping rain water, two pointers O(n)
3. Hash Harbor FREE
Hash maps: find anything in one visit
- Locker Room: Hash map put and get, O(1) each
- Duplicate Parcel: Hash set membership, O(n)
- Frequency Board: Counting with a hash map, O(n)
- Two Sum Harbor: Hash map complement lookup, O(n)
- Anagram Crates: Letter counts in a hash map, O(n)
- Longest Chain: Hash set sequence starts, O(n)
- Smuggler Twins: Prefix sums + hash map, O(n)
4. Binary Peaks PREMIUM
Halve the mountain with binary search
- The Treasure Cave: Binary search, O(log n)
- First Footprint: Binary search for the first match
- Insert the Flag: Lower bound, O(log n)
- Broken Mountain: Search a rotated sorted array, O(log n)
- Square Root Cliff: Binary search on the answer
- Summit: Peak finding, O(log n)
- Peak Guardian: Binary search on the answer, O(n log range)
5. Sorting Factory PREMIUM
Selection, insertion, merge and quick sort
- Selection Belt: Selection sort, O(n²) compares, ≤ n swaps
- Insertion Belt: Insertion sort, fast on nearly sorted data
- Merge Press: Merging two sorted lists, O(n + m)
- Merge Sort Line: Merge sort, O(n log n)
- Pivot Crane: Partitioning around a pivot, O(n)
- Colour Bins: Dutch national flag, one pass
- Overload Foreman: Quick sort, O(n log n) average
6. Mirror Caves PREMIUM
Recursion and backtracking
- Descend the Mirrors: Recursion and the call stack
- Echo Sum: Recursion over an array
- Fast Power: Divide and conquer, O(log n)
- Every Path: Generating subsets by include / exclude, O(2ⁿ)
- Shuffle Hall: Permutations by backtracking, O(n!)
- Word Maze: Backtracking search on a grid
- Queen's Court: N-Queens backtracking with pruning
7. Chain Railway PREMIUM
Linked lists: follow the couplings
- Walk the Train: Traversing a linked list, O(n)
- Couple a Car: Inserting into a linked list, O(1) once found
- Uncouple: Deleting from a linked list
- Middle Car: Tortoise and hare, one pass
- Loop Track: Floyd's cycle detection, O(1) space
- Merge Yards: Merging sorted linked lists, O(n + m)
- Runaway Express: Reversing a linked list in place
8. Stack Tower & Queue Station PREMIUM
Stacks, queues and deques
- Balance the Brackets: Stack: last in, first out
- Undo Button: A stack reverses order
- Ticket Line: Queue: first in, first out
- Plate Calculator: Evaluating postfix with a stack
- Taller Neighbour: Monotonic stack, O(n)
- Two-Door Station: Sliding window maximum with a deque, O(n)
- The Gatekeeper: Largest rectangle in a histogram, monotonic stack
9. Tree Forest PREMIUM
Trees, BSTs and heaps
- Climb the Oak: Preorder, inorder, postorder traversal
- Tallest Tree: Recursive depth, O(n)
- Level by Level: Breadth-first traversal with a queue
- Seed Sorter: Binary search tree insert, O(height)
- Common Root: Lowest common ancestor in a BST
- Lava Pile: Min-heap push and pop, O(log n)
- Elder Treant: Validating a BST with ranges, O(n)
10. Graph Kingdom PREMIUM
DFS, BFS, union-find and shortest paths
- Roads and Towns: Depth-first search
- Ripple Scout: Breadth-first search for shortest paths
- Island Count: Flood fill on a grid
- Quest Order: Topological sort (Kahn's algorithm)
- Clan Merge: Union-find (disjoint sets)
- Toll Roads: Dijkstra's shortest path
- Fog Warlord: Cycle detection in a directed graph