Computer science / interactive lab
Make every step
make sense.
92 algorithms and interview patterns, animated one step at a time. Type your own input, scrub backwards and forwards, and follow the Java code as each line runs. Then check yourself with a short quiz.
- No sign-up
- Java code for every algorithm
- Works on phones
- 92step-by-step visualisations
- 11topics, from sorting to DP
- 66linked to LeetCode problems
- 45quiz questions with explanations
Just added
39 new visualisations, two new topics
Greedy and Bit manipulation join the lab, plus union-find, Floyd-Warshall, permutations, house robber and more. Every one has Java, your own input and a quiz.
- Shell sort
- Jump search
- Search in a rotated sorted array
- First and last position of a value
- Search a sorted 2D matrix
- Median of two sorted arrays
- Remove the Nth node from the end
- Merge two sorted linked lists
- Min stack
- Queue using two stacks
- Circular queue (ring buffer)
- LRU cache (hash map + linked list)
- Maximum depth of a tree
- Lowest common ancestor in a BST
- Invert a binary tree
- Validate a binary search tree
- Kth largest element (min-heap of size k)
- Floyd-Warshall all-pairs shortest paths
- Detect a cycle in a directed graph
- Union-Find (disjoint sets)
- Boyer-Moore majority vote
- Best time to buy and sell stock
- Product of array except self
- Rotate an array by k
- Merge two sorted arrays
- Sliding window maximum
- Longest substring without repeats
- Valid anagram
- Group anagrams
- Fibonacci with memoization
- 1D DP: house robber
- Word break
- 2D DP: unique paths with obstacles
- Backtracking: permutations
- Jump game
- Interval scheduling (non-overlapping)
- Count set bits (Kernighan)
- Single number with XOR
- Subsets with a bitmask
Explore
Every algorithm, step by step
Each one runs on your input, highlights the Java line being executed, and explains the idea, the complexity and the interview angle.
- Sorting10 visualisations
- Searching7 visualisations
- Lists, stacks & queues9 visualisations
- Trees16 visualisations
- Graphs11 visualisations
- Patterns16 visualisations
- Hashing5 visualisations
- Dynamic programming10 visualisations
- Backtracking3 visualisations
- Greedy2 visualisations
- Bit manipulation3 visualisations
- Sorting Sorting race Six sorts get the same input and each plays one step of its animation per tick. A step is roughly one comparison or one move, so the finishing order shows how much work each one does on this input.
- Sorting Bubble sort Walk through the array and swap any neighbors that are out of order. After each pass, the largest remaining value has bubbled to the end.
- Sorting Selection sort Find the smallest value in the unsorted part and swap it to the front. Repeat until nothing is left.
- Sorting Insertion sort Keep the left part sorted. Take the next value (the key) and slide it left past every bigger value.
- SortingNew Shell sort Insertion sort, but first on values that are gap apart. Big gaps move far-away values quickly; the last pass with gap 1 is a normal insertion sort on an almost sorted array.
- Sorting Merge sort Split the array in half until each piece has one value, then merge the pieces back together in order.
- Sorting Quick sort Pick a pivot, move smaller values to its left and bigger ones to its right, then sort each side the same way.
- Sorting Heap sort Turn the array into a max-heap so the biggest value sits at index 0. Swap it to the end, shrink the heap by one, and repair it. Repeat.
- Sorting Counting sort No comparisons at all. Count how many times each value appears, then write the values back from smallest to largest.
- Sorting Radix sort (LSD) Sort by the ones digit, then by the tens digit, keeping ties in their previous order. After the last digit the whole array is sorted, without comparing two values.
- Searching Linear search Check every value from left to right until you find the target or run out of values.
- SearchingNew Jump search On a sorted array, jump ahead √n values at a time until you pass the target, then walk back through that one block with a linear scan.
- Searching Binary search On a sorted array, look at the middle value. If it is too small, throw away the left half. If too big, throw away the right half.
- SearchingNew Search in a rotated sorted array Cut at the middle. One of the two halves is always fully sorted, and you can tell which by comparing its ends. If the target lies inside that sorted half, search there; otherwise search the other half.
- SearchingNew First and last position of a value Run binary search twice. When you hit the target, do not stop: remember the index, then keep going left to find the first copy, or right to find the last.
- SearchingNew Search a sorted 2D matrix Start at the top-right corner. Everything left of it in its row is smaller and everything below it in its column is bigger. Too big: step left and drop that column. Too small: step down and drop that row.
- SearchingNew Median of two sorted arrays Cut the shorter array at i and the longer at j so the two left parts hold half of all values. The cut is right when every left value ≤ every right value: A[i−1] ≤ B[j] and B[j−1] ≤ A[i]. Binary-search i until that holds; the median sits at the cut.
- Lists, stacks & queues Reverse a linked list Walk the list once. At each node, save next, point the node back to prev, then move prev and curr one step forward.
- Lists, stacks & queues Floyd's cycle detection slow moves 1 step, fast moves 2. With a cycle, fast laps slow and they meet. Without one, fast reaches null.
- Lists, stacks & queuesNew Remove the Nth node from the end Move fast n + 1 steps ahead of slow. Then move both until fast falls off the end: slow now sits just before the node to remove.
- Lists, stacks & queuesNew Merge two sorted linked lists A dummy node gives the merged list a fixed start. tail points at its last node. Each step links the smaller of the two front nodes after tail and moves on. When one list ends, link the rest of the other.
- Lists, stacks & queues Stack: valid parentheses Push every opening bracket. A closing bracket must match the top of the stack. At the end, the stack must be empty.
- Lists, stacks & queuesNew Min stack Keep a second stack beside the first. Each push also pushes the minimum so far onto it. Popping both keeps them in step, so the top of the second stack is always the current minimum.
- Lists, stacks & queuesNew Queue using two stacks New values go on the in stack. To dequeue, take from the out stack; if it is empty, pour the whole in stack into it first. Pouring reverses the order, so the oldest value ends up on top.
- Lists, stacks & queuesNew Circular queue (ring buffer) An array of k slots, a head index for the front, and a count. Enqueue writes at (head + count) % k; dequeue reads at head and moves head forward. The % wraps both around the end.
- Lists, stacks & queuesNew LRU cache (hash map + linked list) A hash map finds a key’s node in O(1). A doubly linked list keeps nodes in use order: most recent at the head, least recent at the tail. A hit moves the node to the head; a miss adds at the head and, if full, removes the tail.
- Trees BST insert Start at the root. Go left if the new value is smaller, right if bigger, until you reach an empty spot.
- Trees BST search Each comparison throws away one whole subtree, so a balanced tree is searched in O(log n) steps.
- Trees BST delete Find the node. With zero or one child, its child takes its place. With two children, copy in the smallest value from the right subtree, then delete that one.
- Trees Inorder traversal Left subtree, then the node, then the right subtree.
- Trees Preorder traversal The node first, then its left subtree, then its right subtree.
- Trees Postorder traversal Both subtrees first, the node last.
- Trees Level-order traversal Visit the tree one level at a time from top to bottom, using a queue.
- TreesNew Maximum depth of a tree The depth of an empty tree is 0. Otherwise it is 1 plus the deeper of the two subtrees. Each node waits for both children, then reports up.
- TreesNew Lowest common ancestor in a BST If p and q are both smaller than the node, the answer is on the left. Both bigger, on the right. Otherwise they split here (or one of them is this node): this node is the answer.
- TreesNew Invert a binary tree At each node, swap its left and right children, then invert both subtrees. An empty tree is already inverted.
- TreesNew Validate a binary search tree Each node gets a range (low, high). The root may be anything. Going left, the node’s value becomes the new high; going right, it becomes the new low. A value outside its range breaks the tree.
- Trees Min-heap insert Add the new value at the end of the array, then let it bubble up while it is smaller than its parent.
- Trees Min-heap extract The minimum is always the root. Remove it, move the last value to the root, and let it sink down to the smaller child until the heap is valid.
- TreesNew Kth largest element (min-heap of size k) Keep a min-heap of the k largest values seen so far. Push each value; if the heap grows past k, pop its smallest. At the end the root is the k-th largest.
- Trees AVL tree insert A BST that keeps itself balanced. After each insert, if one side becomes more than 1 level taller, rotate to fix it.
- Trees Trie (prefix tree) Each edge is one letter. Words that share a prefix share the same path. A double ring marks where a full word ends.
- Graphs Breadth-first search Visit the start, then all its neighbors, then their neighbors. A queue keeps nodes in the order they were found.
- Graphs Depth-first search Go as deep as possible along one path, then back up and try the next branch. The call stack remembers where to return.
- Graphs Dijkstra's shortest path Always finalize the closest unfinished node next, then try to improve the distance to each of its neighbors.
- Graphs Bellman-Ford shortest path Relax every edge, V − 1 times. After round i, every shortest path that uses at most i edges is correct. One more round that still improves something means a negative cycle.
- GraphsNew Floyd-Warshall all-pairs shortest paths Allow one more node k as a stopover at a time. For every pair (i, j), going i → k → j might beat the best path found so far. After every k has been tried, all distances are final.
- Graphs Topological sort (Kahn) Count incoming edges (in-degree). Nodes with in-degree 0 can go first. Removing them frees up more nodes.
- GraphsNew Detect a cycle in a directed graph Colour nodes white (new), grey (on the current DFS path) and black (finished). Meeting a grey node again means you walked back into your own path: that edge closes a cycle. Meeting a black node is fine.
- GraphsNew Union-Find (disjoint sets) Every set is a tree; its root names the set. find walks up to the root. union points one root at the other. If both ends of an edge already share a root, that edge closes a cycle.
- Graphs Kruskal's minimum spanning tree Sort edges by weight. Take each edge unless its two ends are already connected. Union-find answers "already connected?" almost instantly.
- Graphs Prim's minimum spanning tree Grow one tree from A. Always add the cheapest edge that reaches a node not yet in the tree.
- Graphs Number of islands (flood fill) Scan every cell. Each time you land on unvisited land, that is a new island: count it, then sink the whole island with DFS so it is never counted again.
- Patterns Sliding window (fixed size) Keep one running sum. When the window slides right, add the value coming in and subtract the value going out.
- Patterns Sliding window (variable size) Grow the window with r until it meets the condition, then shrink it with l as far as it stays valid.
- Patterns Two pointers (opposite ends) Start at both ends. If the sum is too small, move the left pointer right. If too big, move the right pointer left.
- Patterns Container with most water Start with the widest container. Always move the shorter wall inward, because the taller wall can never do better with less width.
- Patterns Trapping rain water Water above a bar = the lower of (tallest wall on its left, tallest wall on its right) minus the bar. Two pointers find this without extra arrays.
- Patterns Fast and slow pointers fast reads every value. slow marks where the next kept value should go.
- Patterns Kadane's algorithm At each value, either extend the current subarray or start fresh here, whichever is bigger. Remember the best you have seen.
- Patterns Prefix sum + hash map If prefix[j] = prefix[i] − k, the values between j and i sum to k. A hash map remembers how often each prefix sum appeared.
- Patterns Monotonic stack The stack holds values still waiting for an answer. A bigger value pops everything smaller than it and becomes their answer.
- Patterns Dutch national flag lo marks where the next 0 goes, hi where the next 2 goes. mid scans the unknown part in between.
- PatternsNew Boyer-Moore majority vote Pair every vote for the candidate with a vote against it, and cancel them. Whatever survives all the cancelling must be the majority, because it has more votes than everything else combined.
- PatternsNew Best time to buy and sell stock Walk the days once. Remember the cheapest price seen so far; selling today earns today minus that price. Keep the best earning.
- PatternsNew Product of array except self out[i] = (product of everything left of i) × (product of everything right of i). One pass left to right stores the left products, a second pass right to left multiplies in the right products.
- PatternsNew Rotate an array by k Reverse the whole array, then reverse the first k values, then reverse the rest. The last k values end up in front, each part in its original order.
- PatternsNew Merge two sorted arrays Keep a pointer at the front of each array. Take the smaller of the two front values, move that pointer, and repeat. When one array runs out, copy the rest of the other.
- PatternsNew Sliding window maximum A deque holds indexes whose values only go down from front to back. A new value pops every smaller value off the back, since those can never be a maximum again. The front is the window maximum; drop it once it slides out.
- Hashing Hash table with chaining hash(key) mod m picks a bucket. Keys that land in the same bucket (a collision) are kept in a short list. Lookup only scans one bucket.
- Hashing Two Sum with a hash map Walk once. For each value, ask the hash map whether its partner (target − value) was already seen. If not, remember this value and its index.
- HashingNew Longest substring without repeats Grow the window to the right one letter at a time. A hash map remembers where each letter was last seen; on a repeat inside the window, jump the left edge just past that earlier copy.
- HashingNew Valid anagram Count every letter of the first word up, and every letter of the second word down. They are anagrams only if every count ends at 0.
- HashingNew Group anagrams Sort the letters of each word. Anagrams give the same sorted key, so a hash map from key to list collects each group in one pass.
- Dynamic programmingNew Fibonacci with memoization fib(n) = fib(n − 1) + fib(n − 2). Plain recursion recomputes the same values and makes about 2^n calls. A memo map stores each answer, so every n is computed once and repeats are instant.
- Dynamic programming 1D DP: climbing stairs Fill a table from the smallest case up. Each cell reuses cells you already filled, so nothing is computed twice.
- Dynamic programmingNew 1D DP: house robber best[i] is the most money from the first i houses. Either skip house i (keep best[i − 1]) or rob it and add it to best[i − 2]. Take the bigger one.
- Dynamic programming 1D DP: coin change dp[i] is the fewest coins for amount i. For each coin c, amount i can be reached from i − c with one more coin.
- Dynamic programming 1D DP: longest increasing subsequence dp[i] is the length of the longest increasing run that ends exactly at a[i]. Look back at every j < i with a smaller value and extend the best one.
- Dynamic programmingNew Word break dp[i] says whether the first i letters can be built from words. dp[0] is true (the empty start). dp[i] is true if some earlier dp[j] is true and the letters from j to i form a word.
- Dynamic programmingNew 2D DP: unique paths with obstacles You can only enter a cell from above or from the left, so paths(r, c) = paths(r − 1, c) + paths(r, c − 1). An obstacle has 0 paths through it.
- Dynamic programming 2D DP: 0/1 knapsack dp[i][w] is the best value using the first i items with capacity w. Either skip item i (cell above) or take it (value + the cell up and to the left).
- Dynamic programming 2D DP: longest common subsequence dp[i][j] is the LCS of the first i letters of A and the first j letters of B. A match adds 1 to the diagonal. Otherwise take the bigger of up and left.
- Dynamic programming 2D DP: edit distance dp[i][j] is the cost to turn the first i letters of A into the first j letters of B. Same letter: copy the diagonal. Otherwise 1 + the cheapest of replace (diagonal), delete (up) or insert (left).
- Backtracking Backtracking: subsets For each value, make a choice: include it or skip it. Go deeper, then undo the choice and try the other branch.
- BacktrackingNew Backtracking: permutations Fill the answer one position at a time. At each position try every value not used yet, go deeper, then give the value back so the next branch can use it.
- Backtracking Backtracking: N-Queens Place one queen per row. Try each column. If it is safe, move to the next row. If no column works, backtrack and move the previous queen.
- GreedyNew Jump game Walk left to right and keep far, the furthest index reachable so far. If you ever stand on an index beyond far, you are stuck. If far reaches the end, you win.
- GreedyNew Interval scheduling (non-overlapping) Sort by end time. Keep an interval if it starts at or after the end of the last one kept. Finishing as early as possible leaves the most room for everything after.
- Bit manipulationNew Count set bits (Kernighan) Subtracting 1 flips the lowest 1 bit to 0 and every 0 below it to 1. So n & (n − 1) erases exactly the lowest 1 bit. Count how many times you can do that before n is 0.
- Bit manipulationNew Single number with XOR XOR is 1 where two bits differ. x ^ x = 0 and x ^ 0 = x, and the order does not matter. So XOR everything: each pair cancels itself, and only the single value is left.
- Bit manipulationNew Subsets with a bitmask Count mask from 0 to 2ⁿ − 1. Bit i of the mask says whether value i is in the subset. Counting in binary therefore lists every subset exactly once.
Nothing matches that.
Your progress
0 of 92 algorithms done
Saved in this browser only. An algorithm counts as done when you’ve opened it and aced its topic quiz.
Badges
Your favourites
Learning paths
Not sure where to start? Follow a path
Each path strings algorithms together in an order that builds on itself. The lab shows your place and the next step.
Coding interview crash course
The patterns that cover most array, string and graph questions.
- Two Sum with a hash map
- Two pointers (opposite ends)
- Sliding window (variable size)
- Binary search
- Kadane's algorithm
- Prefix sum + hash map
- Monotonic stack
- Breadth-first search
- Topological sort (Kahn)
- 1D DP: coin change
- Backtracking: subsets
11 visualisationsStart path →Sorting from scratch
Build intuition from the simplest sort to the race between them.
- Bubble sort
- Insertion sort
- Selection sort
- Merge sort
- Quick sort
- Heap sort
- Counting sort
- Radix sort (LSD)
- Sorting race
9 visualisationsStart path →Trees and graphs
From a single BST insert to shortest paths and spanning trees.
- BST insert
- Inorder traversal
- Level-order traversal
- Min-heap insert
- AVL tree insert
- Breadth-first search
- Depth-first search
- Dijkstra's shortest path
- Kruskal's minimum spanning tree
9 visualisationsStart path →Dynamic programming, gently
Recurrence first, table second: 1D, then 2D, then backtracking.
- 1D DP: climbing stairs
- 1D DP: house robber
- 1D DP: coin change
- 1D DP: longest increasing subsequence
- 2D DP: unique paths with obstacles
- 2D DP: 0/1 knapsack
- 2D DP: longest common subsequence
- 2D DP: edit distance
- Backtracking: subsets
- Backtracking: permutations
- Backtracking: N-Queens
11 visualisationsStart path →Interview round two
The next tier of favourites: windows over strings, greedy choices, union-find and bit tricks.
- Longest substring without repeats
- Boyer-Moore majority vote
- Remove the Nth node from the end
- Maximum depth of a tree
- Lowest common ancestor in a BST
- Jump game
- Interval scheduling (non-overlapping)
- Union-Find (disjoint sets)
- Floyd-Warshall all-pairs shortest paths
- Single number with XOR
- Count set bits (Kernighan)
- Subsets with a bitmask
12 visualisationsStart path →
Big-O playground
Feel how fast each complexity grows
Drag n and watch the curves pull apart. Hover the chart to read every curve at one n. The table turns the counts into real time at a billion simple steps per second.
Cheat sheet
Every complexity on one page
Best, average and worst time plus extra space for every algorithm in the lab. Filter it, sort it, and click a name to watch it run.
| Best | Average | Worst | Space | |||
|---|---|---|---|---|---|---|
| Bubble sort | Sorting | Beginner | O(n) | O(n²) | O(n²) | O(1) |
| Selection sort | Sorting | Beginner | O(n²) | O(n²) | O(n²) | O(1) |
| Insertion sort | Sorting | Beginner | O(n) | O(n²) | O(n²) | O(1) |
| Shell sort New | Sorting | Intermediate | O(n log n) | O(n^1.3) | O(n²) | O(1) |
| Merge sort | Sorting | Intermediate | O(n log n) | O(n log n) | O(n log n) | O(n) |
| Quick sort | Sorting | Intermediate | O(n log n) | O(n log n) | O(n²) | O(log n) |
| Heap sort | Sorting | Advanced | O(n log n) | O(n log n) | O(n log n) | O(1) |
| Counting sort | Sorting | Intermediate | O(n + k) | O(n + k) | O(n + k) | O(k) |
| Radix sort (LSD) | Sorting | Intermediate | O(d·(n + 10)) | O(d·(n + 10)) | O(d·(n + 10)) | O(n + 10) |
| Linear search | Searching | Beginner | O(1) | O(n) | O(n) | O(1) |
| Jump search New | Searching | Beginner | O(1) | O(√n) | O(√n) | O(1) |
| Binary search | Searching | Beginner | O(1) | O(log n) | O(log n) | O(1) |
| Search in a rotated sorted array New | Searching | Intermediate | O(1) | O(log n) | O(log n) | O(1) |
| First and last position of a value New | Searching | Intermediate | O(log n) | O(log n) | O(log n) | O(1) |
| Search a sorted 2D matrix New | Searching | Intermediate | O(1) | O(r + c) | O(r + c) | O(1) |
| Median of two sorted arrays New | Searching | Intermediate | O(1) | O(log min(m, n)) | O(log min(m, n)) | O(1) |
| Reverse a linked list | Lists, stacks & queues | Beginner | O(n) | O(n) | O(n) | O(1) |
| Floyd's cycle detection | Lists, stacks & queues | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Remove the Nth node from the end New | Lists, stacks & queues | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Merge two sorted linked lists New | Lists, stacks & queues | Intermediate | O(n + m) | O(n + m) | O(n + m) | O(1) |
| Stack: valid parentheses | Lists, stacks & queues | Beginner | O(n) | O(n) | O(n) | O(n) |
| Min stack New | Lists, stacks & queues | Intermediate | O(1) | O(1) | O(1) | O(n) |
| Queue using two stacks New | Lists, stacks & queues | Intermediate | O(1) | O(1)* | O(n) | O(n) |
| Circular queue (ring buffer) New | Lists, stacks & queues | Intermediate | O(1) | O(1) | O(1) | O(k) |
| LRU cache (hash map + linked list) New | Lists, stacks & queues | Intermediate | O(1) | O(1) | O(1) | O(capacity) |
| BST insert | Trees | Beginner | O(log n) | O(log n) | O(n) | O(h) |
| BST search | Trees | Beginner | O(log n) | O(log n) | O(n) | O(h) |
| BST delete | Trees | Intermediate | O(log n) | O(log n) | O(n) | O(h) |
| Inorder traversal | Trees | Beginner | O(n) | O(n) | O(n) | O(h) |
| Preorder traversal | Trees | Beginner | O(n) | O(n) | O(n) | O(h) |
| Postorder traversal | Trees | Beginner | O(n) | O(n) | O(n) | O(h) |
| Level-order traversal | Trees | Beginner | O(n) | O(n) | O(n) | O(w) |
| Maximum depth of a tree New | Trees | Beginner | O(n) | O(n) | O(n) | O(h) |
| Lowest common ancestor in a BST New | Trees | Intermediate | O(log n) | O(log n) | O(n) | O(1) |
| Invert a binary tree New | Trees | Intermediate | O(n) | O(n) | O(n) | O(h) |
| Validate a binary search tree New | Trees | Intermediate | O(n) | O(n) | O(n) | O(h) |
| Min-heap insert | Trees | Intermediate | O(1) | O(log n) | O(log n) | O(n) |
| Min-heap extract | Trees | Intermediate | O(log n) | O(log n) | O(log n) | O(n) |
| Kth largest element (min-heap of size k) New | Trees | Intermediate | O(n log k) | O(n log k) | O(n log k) | O(k) |
| AVL tree insert | Trees | Advanced | O(log n) | O(log n) | O(log n) | O(n) |
| Trie (prefix tree) | Trees | Advanced | O(L) | O(L) | O(L) | O(total letters) |
| Breadth-first search | Graphs | Beginner | O(V+E) | O(V+E) | O(V+E) | O(V) |
| Depth-first search | Graphs | Beginner | O(V+E) | O(V+E) | O(V+E) | O(V) |
| Dijkstra's shortest path | Graphs | Advanced | O((V+E) log V) | O((V+E) log V) | O((V+E) log V) | O(V) |
| Bellman-Ford shortest path | Graphs | Advanced | O(V·E) | O(V·E) | O(V·E) | O(V) |
| Floyd-Warshall all-pairs shortest paths New | Graphs | Advanced | O(V³) | O(V³) | O(V³) | O(V²) |
| Topological sort (Kahn) | Graphs | Intermediate | O(V + E) | O(V + E) | O(V + E) | O(V) |
| Detect a cycle in a directed graph New | Graphs | Intermediate | O(V + E) | O(V + E) | O(V + E) | O(V) |
| Union-Find (disjoint sets) New | Graphs | Advanced | O(α(n)) | O(α(n)) | O(α(n)) | O(V) |
| Kruskal's minimum spanning tree | Graphs | Advanced | O(E log E) | O(E log E) | O(E log E) | O(V) |
| Prim's minimum spanning tree | Graphs | Advanced | O(E log V) | O(E log V) | O(E log V) | O(V + E) |
| Number of islands (flood fill) | Graphs | Intermediate | O(R·C) | O(R·C) | O(R·C) | O(R·C) |
| Sliding window (fixed size) | Patterns | Beginner | O(n) | O(n) | O(n) | O(1) |
| Sliding window (variable size) | Patterns | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Two pointers (opposite ends) | Patterns | Beginner | O(1) | O(n) | O(n) | O(1) |
| Container with most water | Patterns | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Trapping rain water | Patterns | Advanced | O(n) | O(n) | O(n) | O(1) |
| Fast and slow pointers | Patterns | Beginner | O(n) | O(n) | O(n) | O(1) |
| Kadane's algorithm | Patterns | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Prefix sum + hash map | Patterns | Advanced | O(n) | O(n) | O(n) | O(n) |
| Monotonic stack | Patterns | Intermediate | O(n) | O(n) | O(n) | O(n) |
| Dutch national flag | Patterns | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Boyer-Moore majority vote New | Patterns | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Best time to buy and sell stock New | Patterns | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Product of array except self New | Patterns | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Rotate an array by k New | Patterns | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Merge two sorted arrays New | Patterns | Intermediate | O(n + m) | O(n + m) | O(n + m) | O(n + m) |
| Sliding window maximum New | Patterns | Intermediate | O(n) | O(n) | O(n) | O(k) |
| Hash table with chaining | Hashing | Beginner | O(1) | O(1) | O(n) | O(n + m) |
| Two Sum with a hash map | Hashing | Beginner | O(1) | O(n) | O(n) | O(n) |
| Longest substring without repeats New | Hashing | Intermediate | O(n) | O(n) | O(n) | O(k) |
| Valid anagram New | Hashing | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Group anagrams New | Hashing | Intermediate | O(n·k log k) | O(n·k log k) | O(n·k log k) | O(n·k) |
| Fibonacci with memoization New | Dynamic programming | Intermediate | O(n) | O(n) | O(n) | O(n) |
| 1D DP: climbing stairs | Dynamic programming | Beginner | O(n) | O(n) | O(n) | O(n) |
| 1D DP: house robber New | Dynamic programming | Beginner | O(n) | O(n) | O(n) | O(n) |
| 1D DP: coin change | Dynamic programming | Intermediate | O(n·k) | O(n·k) | O(n·k) | O(n) |
| 1D DP: longest increasing subsequence | Dynamic programming | Intermediate | O(n²) | O(n²) | O(n²) | O(n) |
| Word break New | Dynamic programming | Intermediate | O(n²) | O(n²) | O(n²) | O(n) |
| 2D DP: unique paths with obstacles New | Dynamic programming | Intermediate | O(R·C) | O(R·C) | O(R·C) | O(R·C) |
| 2D DP: 0/1 knapsack | Dynamic programming | Advanced | O(n·W) | O(n·W) | O(n·W) | O(n·W) |
| 2D DP: longest common subsequence | Dynamic programming | Advanced | O(m·n) | O(m·n) | O(m·n) | O(m·n) |
| 2D DP: edit distance | Dynamic programming | Advanced | O(m·n) | O(m·n) | O(m·n) | O(m·n) |
| Backtracking: subsets | Backtracking | Intermediate | O(n·2ⁿ) | O(n·2ⁿ) | O(n·2ⁿ) | O(n) |
| Backtracking: permutations New | Backtracking | Intermediate | O(n·n!) | O(n·n!) | O(n·n!) | O(n) |
| Backtracking: N-Queens | Backtracking | Advanced | O(n!) | O(n!) | O(n!) | O(n) |
| Jump game New | Greedy | Intermediate | O(n) | O(n) | O(n) | O(1) |
| Interval scheduling (non-overlapping) New | Greedy | Intermediate | O(n log n) | O(n log n) | O(n log n) | O(1) |
| Count set bits (Kernighan) New | Bit manipulation | Beginner | O(1) | O(k) | O(k) | O(1) |
| Single number with XOR New | Bit manipulation | Beginner | O(n) | O(n) | O(n) | O(1) |
| Subsets with a bitmask New | Bit manipulation | Intermediate | O(n·2ⁿ) | O(n·2ⁿ) | O(n·2ⁿ) | O(1) |
Nothing matches that filter.
How it works
Watch it, then explain it
- Pick an algorithmSorting, trees, graphs, DP or one of the interview patterns. It starts playing straight away.
- Use your own inputType values, a graph, two words or a grid, or hit Random. Edge cases are the best teachers.
- Step through itPause, scrub backwards, slow down to ¼×. The matching Java line lights up on every step.
- Check yourselfEach topic ends with a quiz that explains the answers, so you can say why, not just what.
Inside the lab
Built for understanding, not memorising
- Java you can copyEvery visualisation shows real, interview-ready Java and highlights the line being executed.
- Interview angleThe LeetCode problems each pattern solves, how to spot it, and the follow-up you will be asked.
- Sorting raceSix sorts on the same input, side by side. Reversed and nearly sorted inputs change the winner.
- Your own inputsValues, targets, weighted graphs, words, grids and bracket strings, all checked as you run them.
- Keyboard friendlySpace to play, arrows to step, [ ] to switch algorithm, Ctrl K to search.
- Share your exact inputOne click copies a link that opens the algorithm with the values you typed, ready for a friend or a study group.
- Narration and step listTurn on Narrate to hear each step read aloud, or open the full step list and jump anywhere.
- Favourites and notesStar the algorithms you want to revise and write your own notes beside the code. Both stay in your browser.
- Streaks and badgesLearn a little every day. Streaks, badges and confetti for perfect quizzes keep the momentum going.
- Big-O playgroundDrag n and watch O(log n), O(n²) and O(2ⁿ) pull apart, then check the cheat sheet for every algorithm.
- Two new topicsGreedy and Bit manipulation join sorting, trees, graphs, DP and the rest, each with its own quiz.
- Surprise meNot sure what to study next? Press R in the lab for an algorithm you have not opened yet.