warming up your workspace

Data Structures & Algorithms

Crack the coding interview: build every data structure from scratch, master the patterns, from arrays and hashing to graphs and dynamic programming.

11 projects, 275 hands-on levels, run in your browser.

Syllabus

  • Foundations: code through algorithms: Never written code before? Start here. You will learn the basics of Python, output, variables, types, decisions, loops, and functions, through the building blocks of algorithms: values, indexes, searches, and totals. By the end you are ready for Project 1.
  • Complexity, Arrays & Hashing: Every interview starts here. Learn to reason about cost with Big-O, get fluent with the array techniques that show up everywhere (prefix sums, in-place two pointers, Kadane), then unlock the single most useful tool in the interview toolkit: the hash map. By the end you can turn brute-force O(n squared) scans into clean O(n) solutions.
  • Two Pointers & Sliding Window: Two of the highest-yield interview patterns. Two pointers walk an array from both ends or at two speeds to solve in O(n) what looks like it needs O(n squared). The sliding window keeps a running answer over a moving range so you never recompute from scratch. Master these and a huge slice of array and string problems fall.
  • Stacks, Queues & Strings: Build the two simplest data structures from scratch, then wield them. A stack (last in, first out) powers parsing, matching, and the monotonic-stack pattern that answers 'next greater element' in O(n). A queue (first in, first out) drives order-preserving simulations. Along the way, sharpen the string-processing reflexes interviews lean on.
  • Binary Search & Sorting: Sorted data is a superpower. Binary search halves the search space each step for O(log n) lookups, and the same idea generalizes to searching over an answer (the smallest speed, the least capacity). Build the classic sorts to own divide-and-conquer, then apply sorting to the interval problems that show up constantly.
  • Linked Lists: A linked list trades random access for cheap insertion and the pointer-rewiring skills interviewers love to probe. Build the node, traverse it, then master the moves: reverse, find the middle and cycles with fast and slow pointers, merge, reorder, and build an LRU cache. Finish by sorting a list with merge sort.
  • Trees & Binary Search Trees: Trees turn recursion into a reflex. Build a binary tree, traverse it depth-first and breadth-first, then reason about depth, balance, and diameter. Add the ordering invariant of a binary search tree to get O(log n) lookups, and finish with the path and ancestor problems interviewers love.
  • Heaps, Priority Queues & Tries: Two specialist structures with huge payoff. A heap keeps the smallest (or largest) element one O(log n) operation away, which is the key to top-K, streaming medians, and merging. A trie stores strings by shared prefix for fast lookup and autocomplete. Build each from scratch, then reach for the library version.
  • Graphs & Advanced Graphs: Graphs model everything with relationships, and most graph interview problems are a traversal in disguise. Build the adjacency list, traverse with BFS and DFS, flood-fill grids, order tasks with topological sort, group with union-find, and find shortest paths with Dijkstra. The patterns here unlock a whole tier of problems.
  • Recursion, Backtracking & Greedy: Two ways to make decisions. Backtracking explores every choice, undoing each before trying the next, which generates subsets, permutations, and solves constraint puzzles. Greedy commits to the locally best choice and never looks back, which is faster but only correct for the right problems. Learn to wield both, and to tell them apart.
  • Dynamic Programming + Capstone: The pattern that scares candidates most, demystified. Dynamic programming solves a problem by combining answers to overlapping subproblems, stored so each is computed once. Start with 1-D recurrences (stairs, robbery, coins), move to 2-D grids and strings (paths, edit distance), then knapsack. The final chapter is a mixed gauntlet, your mock interview.

Key concepts

  • Adjacency list: A graph representation where each node stores the neighbors reachable from it. It is space-efficient for sparse graphs and is the usual input shape for DFS, BF…
  • Array: A contiguous, indexable sequence of values. In Python the closest everyday structure is a list ; DSA problems use arrays for scans, prefix sums, two-pointer te…
  • Backtracking: A recursive search pattern that builds a candidate, explores it, then undoes the choice. It is used for permutations, combinations, subsets, constraint puzzles…
  • Binary search: Repeatedly halves a sorted search space by asking whether the answer is left or right of the midpoint. Beyond arrays, it can search over an answer range when a…
  • Binary search tree: A binary tree where left descendants are smaller and right descendants are larger than the node. This ordering supports search and validates many recursive bou…
  • Breadth-first search: A traversal that explores all nodes at the current distance before moving farther. BFS is the standard shortest-path method for unweighted graphs and level-ord…
  • Depth-first search: A traversal that explores one branch as far as possible before backtracking. DFS appears in trees, graphs, connected components, cycle detection, topological r…
  • Dijkstra's algorithm: A shortest-path algorithm for graphs with nonnegative edge weights. It repeatedly expands the currently cheapest known node using a priority queue until all sh…
  • Dynamic programming: A method for problems with overlapping subproblems and optimal substructure. Instead of recomputing the same state repeatedly, DP stores answers and combines t…
  • Fast/slow pointers: A linked-list technique where one pointer advances faster than another. It detects cycles, finds middle nodes, locates cycle starts, and avoids storing every v…
  • Graph: A set of nodes connected by edges. Graph problems model networks, dependencies, grids, relationships, and routes, then use traversal or shortest-path algorithm…
  • Greedy algorithm: An algorithm that makes the locally best choice at each step and never revisits it. Greedy works only when local choices can be proven to lead to a global opti…
  • Hash map: A key-value table that usually gives O(1) average lookup, insert, and delete. It is the main tool for counting frequencies, remembering seen values, and turnin…
  • Heap: A tree-shaped priority structure where the smallest or largest item can be removed quickly. In Python, heapq is a min-heap used for top-k, merging sorted strea…
  • Linked list: A sequence made of nodes where each node points to the next node. Linked-list problems test pointer rewiring, sentinel nodes, cycle detection, reversal, mergin…
  • Memoization: Top-down dynamic programming: write the natural recursive solution, cache each state's answer, and reuse it when the state appears again. It is often the f…
  • Monotonic stack: A stack kept in increasing or decreasing order by popping weaker candidates before pushing a new value. It solves nearest greater/smaller element, stock span,…
  • Prefix sum: A running total where prefix[i] stores the sum before or through index i . It turns range-sum queries into subtraction and often pairs with a hash map to count…
  • Priority queue: A queue where the next item is chosen by priority rather than arrival time. It is commonly implemented with a heap and used when the next cheapest, earliest, o…
  • Queue: A first-in, first-out structure: the oldest item is removed first. It is the natural structure for BFS, level-order tree traversal, and processing work in arri…
  • Set: A collection of unique values optimized for membership checks. Use a set when you only care whether something has appeared, not how many times or where it appe…
  • Sliding window: A two-pointer pattern that keeps a moving subarray or substring while updating its state incrementally. It is ideal for longest, shortest, or counted ranges un…
  • Sorting: Putting values into a defined order so later logic becomes simpler. Sorting often costs O(n log n), but it unlocks binary search, two pointers, interval mergin…
  • Stack: A last-in, first-out structure: the newest item is removed first. It models nested structure, undo behavior, DFS, and problems where you need to remember unres…
  • Tabulation: Bottom-up dynamic programming: fill a table in an order where every needed smaller state is already known. It usually avoids recursion depth issues and makes s…
  • Tree: A connected structure with parent-child relationships and no cycles. Tree problems usually rely on recursion, DFS, BFS, or combining answers from subtrees.
  • Trie: A prefix tree for strings where each edge represents a character. Tries make prefix lookup, autocomplete, word search, and dictionary matching efficient when m…
  • Two pointers: A technique that moves two indices through a sequence, often from opposite ends or at different speeds. It works when the problem has order, sorted input, or a…