In this course, you’ll practice problems where the data is a network of connections or a stream where only the top few items matter. Graphs and heaps are interview favorites because the brute-force answer is usually easy to find and painfully slow, and because the step from one to the other is exactly the kind of reasoning interviewers want to hear out loud.
What You’ll Practice
- Graphs and grids: turn a list of edges into a
Mapof neighbors, keep aSetof what you’ve visited, walk depth-first to find out whether something is reachable, and walk level by level to count the fewest steps. A grid of pixels or game tiles is a graph too, with its neighbors computed on the fly. - Heaps: keep the smallest or largest item ready at the top while new items arrive. You’ll write a
MinHeapclass, because JavaScript doesn’t have one, and then use it to pick the top k items and merge sorted streams.
You’ll also run into JavaScript details that interviewers like to probe:
- Why a plain object makes a risky adjacency list when a key is named
constructor - Why
seen.has([2, 3])isfalseright afterseen.add([2, 3]) - Why
shift()turns a breadth-first search on a big graph quadratic - Why a recursive flood fill throws a
RangeErroron a large canvas - Why
sort()with no comparator puts10before9, and why subtracting two date strings givesNaN - Why
localeCompare()and<disagree about where"über"goes
How the Course Works
- Concept lessons introduce graphs and heaps with short examples you can run.
- Exercises run in your browser on Node 26, and you don’t need to install anything. Each problem is set in a web-app scenario. Get a working solution first. Then a bonus test plays the interviewer’s follow-up: does your solution still work when the graph has tens of thousands of nodes or the log has hundreds of thousands of lines?
- An AI-code review hands you a plausible function with hidden bugs. Your job is to find them and fix them, which is the skill you need whenever an assistant writes code for you.
- Recaps at the end of each section let Mentor AI look at your attempts and talk through whatever hasn’t clicked yet.
- Mixed Practice ends the course with problems that combine both patterns, a quiz on choosing the right one, and a mock interview.
Before You Start
You should be comfortable writing JavaScript functions and classes and working with arrays, Map, and Set. Knowing what O(n), O(n log n), and O(n²) mean helps.
Graphs build on the trees from the fourth course, and breadth-first search uses the queue from the third course. You don’t need to finish those courses first, though. When a graph problem gets tangled, sketch the nodes and arrows for a small example before you write any code. Interviewers like to see that, too.
Your Cheat Sheets
Two cheat sheets go with every course in this learning path. Keep them open while you practice. The patterns sheet shows how to spot each interview pattern, with a JavaScript template for it, and the complexity sheet lists what common JavaScript operations cost in time and space.