← Back to posts

Algorithm Patterns in JavaScript: Series Roadmap

Most coding problems you meet in interviews or on practice sites reuse a small set of techniques. Spot that a problem is really about counting, for example, and a Map replaces the nested loop you would otherwise write.

Each part of this series covers one technique with two problems solved in full, the easier one first. Some parts add a third, shorter problem where the same idea shows up in a different setting. All the code is JavaScript, and every solution states its time and space complexity with a short explanation of where the numbers come from.

How to read it

Read the parts in order if you can, since later ones refer back to earlier ones (the sliding window part reuses the counting from part 1, for example). Skip any technique you already know. Each part ends with a small code template you can copy.

The parts

Foundations: hashing and arrays

  1. Hash maps and frequency counting
  2. Two pointers (coming soon)
  3. Sliding window (coming soon)
  4. Prefix sums (coming soon)

Data structures

  1. Stacks (coming soon)
  2. Linked list basics (coming soon)
  3. Fast and slow pointers (coming soon)
  4. Binary search (coming soon)

Recursion and optimization

  1. Recursion and backtracking (coming soon)
  2. Greedy algorithms (coming soon)
  3. Dynamic programming (coming soon)

Three of the parts are older posts that I'm expanding. Anagram, from March 2025, is now part 1, and Valid Parentheses and Climbing Stairs will become parts 5 and 11. They keep their original dates, so go by the numbers in this list, not by the date on the post.

Which technique fits?

Technique Try it when the problem asks for...
Hash map counting things, or finding a value you saw earlier
Two pointers a pair in sorted input, or comparing the two ends of an array
Sliding window the longest or shortest contiguous stretch that meets a condition, when adding an element only pushes it one way (a sum of non-negative numbers, the count of distinct letters)
Prefix sums sums of many ranges in the same array
Stack matching brackets, or "the most recent item first"
Linked list basics reversing or merging linked lists
Fast and slow pointers a cycle in a linked list, or its middle
Binary search the first position in sorted data where something becomes true
Backtracking every combination or every subset
Greedy a choice that looks best right now and never has to be undone
Dynamic programming the number of ways to do something, or a minimum cost built from smaller answers

Where to practice

The problems here are written for this series. For more practice, these sites have plenty of problems that use the same techniques:


Profile picture

Written by Florin — full-stack & AI engineer.