Data structures and algorithms are the part of coding interviews most people dread. A lot of tutorials start with code. We wanted to start with something you already understand.

Every data structure is something you've seen before

  • Stack → a pile of plates. You add to the top and take from the top. Last in, first out. That's your browser's Back button and every function call in your program.
  • Queue → the line at a coffee shop. First come, first served.
  • Array → a row of numbered lockers. Know the number, walk straight to it.
  • Hash map → a coat check. The ticket tells you exactly which hook your coat is on.
  • Linked list → a train. Each car only knows the car behind it.
  • Tree → a family tree, drawn upside down with the root at the top.
  • Graph → a subway map. Stations are nodes, tracks are edges.
  • Binary search → finding a name in a phone book. Open the middle, throw away half.
  • Dynamic programming → writing each answer down once so you never work it out twice.

Once the picture clicks, the code is mostly bookkeeping. Here's an example.

Example: the sliding window

Problem: you have your step counts for each (in thousands). What's the shortest run of
consecutive days with a total of at least 7?

The brute-force way checks every possible run: O(n²). The picture that helps is a window sliding along the days:

  1. Grow the window to the right until the total reaches 7. [2, 3, 1, 2] = 8 → length 4
  2. Shrink it from the left while the total is still at least 7, recording the length each time. [1, 2, 4] = 7 → length 3
  3. Keep going to the end. [4, 3] = 7 → length 2

Each day enters the window once and leaves it o

def shortest_stretch(days, target): best = float("inf") total = left = 0 for right, steps in enumerate(days): total += steps # grow  while total >= target: # sugh  best = min(best, right - left + 1) total -= days[left] left += 1 return 0 if best == float("inf") else best print(shortest_stretch([2, 3, 1, 2, 4, 3], 7)) 
function shortestStretch(days, target) { let best = Infinity, total = 0, left = 0; for (let right = 0; right < days.length; righ total += days[right]; // grow while (total >= target) { // ough best = Math.min(best, right - left + 1); total -= days[left++]; } } return best === Infinity ? 0 : best; } console.log(shortestStretch([2, 3, 1, 2, 4, 3], 

The pattern to remember: grow from the right, shrink from the left, and record the answer while the window is valid.
The same shape solves "longest substring withoud a lot of other window problems.

Try it yourself

We put this approach into a free practice secti

  • 8 short lessons, from arrays and hashing ch with a picture, diagrams you step through with Back/Next, and a quick quiz
  • 24 original interview problems (3 per tope in your browser in Python or JavaScript, with tests that show exactly which cases pass. Your code runs privately in your own browser.
  • Hints one step at a time when you're stucsolution with time and space complexity

There's also a weekly leaderboard if you liign in (free) to earn 10/20/30 points for
easy/medium/hard problems. It resets every Monday, and each week's top learners get a free, verifiable certificate.
Solutions you viewed or pasted don't earn point

You don't need an account to read or solve:

👉 Start with Topic 1: Arrays and hashing
👉 See all 8 topics