A blog series
DSA for Interviews, From Zero
Data structures and algorithms for coding interviews, starting from the very first loop. Every idea is traced step by step and then practised on interview-style questions with full answers, so that it stays with you long term.
- Started
- 2026
- Progress
- 60 / 60 lessons
- Parts
- 15
- Language
- JavaScript
How the series is organised
Fifteen parts, each building on the one before. Never written a loop? Start at Lesson 01 — it assumes nothing. Already comfortable with loops and arrays? Jump to Part 2.
- 1Programming From ZeroVariables, conditions, for and while loops, functions, arrays, strings and maps — in JavaScript, traced line by line.Lessons 1–10
- 2Thinking Like a Problem-SolverReading a problem, Big-O, basic maths, your first recursion and counting with a hash map.Lessons 11–15
- 3SortingSelection, bubble and insertion sort to understand sorting; merge and quick sort to use it.Lessons 16–18
- 4Arrays and the First PatternsPrefix sums, two pointers, sliding windows, Kadane's algorithm and matrices.Lessons 19–25
- 5Hashing PatternsTwo Sum, the “seen before?” technique, frequency maps and grouping.Lessons 26–27
- 6Binary SearchHalving a sorted array, then binary search on the answer.Lessons 28–29
- 7StringsPalindromes, reversing, counting and substring windows.Lessons 30–31
- 8Recursion and BacktrackingRecursion trees, subsets, permutations and standard backtracking problems.Lessons 32–34
- 9Linked ListsBuild one, reverse it, and the fast/slow pointer pattern.Lessons 35–37
- 10Stacks and QueuesValid parentheses, queues, deques and the monotonic stack.Lessons 38–40
- 11TreesTraversals, BFS and DFS on trees, binary search trees, LCA.Lessons 41–45
- 12Heaps, Greedy and IntervalsTop-K with heaps, greedy choices and interval merging.Lessons 46–48
- 13GraphsStoring graphs, BFS/DFS, topological sort, shortest paths, union-find.Lessons 49–53
- 14Dynamic ProgrammingFrom recursion to memoisation, then 1-D, 2-D and string DP.Lessons 54–57
- 15Extras and the InterviewTries, bit tricks, the interview playbook and a revision plan.Lessons 58–60
How every lesson works
- The idea in plain words — a real-life picture before any code.
- A dry run — every variable written down at every step, plus an interactive tracer you can step through.
- Interview-style questions — each with examples, a hint, and a full answer with the reasoning. Try first, then open the answer.
- Make it stick — a short recall exercise and a revisit schedule (tomorrow, 3 days, a week), because recalling beats re-reading.
Contents
Part 1 · Programming From Zero
Variables, conditions, for and while loops, functions, arrays, strings and maps — in JavaScript, traced line by line.
- Lesson 01What a Program Is, and How to Run OneA program is a list of instructions run top to bottom. Run your first JavaScript, read its output, and learn to predict exactly what prints.Topics · What a program and a statement are · Running JavaScript: browser console, Node.js, a .js file · console.log and printing several values · Top-to-bottom execution order · Comments · Reading errors: SyntaxError, ReferenceError, TypeError · The dry-run habit: predict, then run12 min
- Lesson 02Variables and Data TypesNamed boxes for values: numbers, strings and booleans, and the operators that combine them — including % and Math.floor, which appear in almost every DSA problem.Topics · let and const · Naming rules and camelCase · number, string, boolean, undefined, null and typeof · Arithmetic operators and their order · % (remainder) and Math.floor (whole division) · Useful Math functions: abs, min, max, round, sqrt · Joining text and template literals · Converting between text and numbers · Shorthand operators: +=, ++16 min
- Lesson 03Conditions: if / elseTeach the program to make decisions. Comparisons, && and ||, else-if chains, and common questions: even or odd, largest of three, leap year.Topics · Comparison operators and === vs == · if, else and else-if chains · Logical operators &&, || and ! · Short-circuit evaluation · Truthy and falsy values · The ternary operator ? : · The switch statement · Testing boundary values1 LeetCode problem to practise18 min
- Lesson 04The for LoopThe most important idea in this series. Start, condition and update, traced step by step with a dry-run table until the pattern is clear.Topics · Why loops exist · The three parts: start, check, update · The exact order of execution · Counting up, down and in steps · How many times a loop runs · The accumulator pattern: sum, product, count · Flags, break and continue · Off-by-one errors and how to avoid them3 LeetCode problems to practise22 min
- Lesson 05The while LoopRepeat while a condition is true. Taking a number apart digit by digit, and a clear rule for choosing between for and while.Topics · while syntax and the order of execution · The digit loop: n % 10 and Math.floor(n / 10) · Building a number digit by digit (reverse) · Infinite loops and how to avoid them · do … while · Choosing between for and while4 LeetCode problems to practise18 min
- Lesson 06Nested Loops and PatternsA loop inside a loop is a grid: rows outside, columns inside. Built up with star and number patterns until you can draw any shape.Topics · The grid model: rows and columns · Building a row, then printing it · Inner limits that depend on the outer variable · A three-question recipe for any pattern · Triangles, pyramids and hollow shapes · Counting pairs, and how much work nested loops do2 LeetCode problems to practise20 min
- Lesson 07FunctionsPackage a piece of logic, give it inputs and get a result back. The difference between return and console.log, and why every interview answer is a function.Topics · Defining and calling functions · Parameters, arguments and default values · return vs console.log · Scope: variables inside stay inside · Early return · Arrow functions · Passing values vs passing references · Helper functions and the LeetCode answer format3 LeetCode problems to practise18 min
- Lesson 08ArraysMany values in one variable, numbered from 0. Reading, updating, looping and the first real interview questions on arrays.Topics · Indexes, length, reading and updating · Looping: index loop and for…of · push, pop, shift and unshift · Four core patterns: accumulate, best so far, count, search · Linear search · References and copying arrays · Built-in methods: includes, indexOf, slice, splice, sort, map, filter, reduce · Edge cases: empty, one element, duplicates4 LeetCode problems to practise24 min
- Lesson 09StringsText behaves like an array of characters that cannot be changed in place. Looping over characters, reversing, palindromes and counting.Topics · Indexing and length · Immutability: building new strings · Looping over characters · Character checks and character codes · Common methods: toLowerCase, trim, includes, indexOf, slice, split, join · Two pointers on a string · Edge cases: empty strings, case, spaces4 LeetCode problems to practise20 min
- Lesson 10Objects, Map and SetLook values up by name instead of by position. The counting pattern behind a large share of interview questions.Topics · Objects: records with named fields · Map: set, get, has, delete, size · The frequency-map pattern · Set: add, has and uniqueness · Why lookups are fast · Arrays of objects · Choosing between array, object, Map and Set5 LeetCode problems to practise20 min
Part 2 · Thinking Like a Problem-Solver
Reading a problem, Big-O, basic maths, your first recursion and counting with a hash map.
- Lesson 11How to Read a ProblemInput, output, constraints, examples and edge cases — and solving it by hand before writing any code.Topics · Inputs, outputs and constraints · Working through the examples by hand · Listing edge cases · Brute force first, then improve · A step-by-step method for every problem · Explaining your thinking out loud5 LeetCode problems to practise20 min
- Lesson 12Big-O: Counting the StepsHow many times does the loop run? Reading time and space complexity from code, and from the constraints of a problem.Topics · Why we count steps, not seconds · O(1), O(n), O(n²), O(log n), O(n log n) · Dropping constants and smaller terms · Space complexity · Best, average and worst case · Reading the constraints to choose an approach4 LeetCode problems to practise24 min
- Lesson 13Basic Maths for DSADigits, divisors, primes, the sieve, GCD and LCM, and fast powers.Topics · Digit problems revisited · All divisors in √n steps · Prime check and the Sieve of Eratosthenes · GCD and LCM with Euclid · Remainders and modular arithmetic · Fast exponentiation7 LeetCode problems to practise26 min
- Lesson 14Recursion BasicsA function that calls itself, a base case that stops it, and the call stack underneath.Topics · Base case and recursive case · The call stack during recursion · Printing 1 to N and N to 1 · Sum and factorial · Recursion on arrays and strings · Multiple recursive calls: Fibonacci · Stack overflow and recursion vs loops3 LeetCode problems to practise24 min
- Lesson 15Basic HashingCounting with arrays and maps, how a hash table works inside, and why lookup becomes instant.Topics · Counting with an array (fixed range, 26 letters) · Counting with a Map (any values) · Answering frequency queries · Highest and lowest frequency · How a hash table works: hash function, buckets, collisions6 LeetCode problems to practise24 min
Part 3 · Sorting
Selection, bubble and insertion sort to understand sorting; merge and quick sort to use it.
- Lesson 16Selection, Bubble and Insertion SortThree simple sorts that show what sorting really does.Topics · What sorting means, and stability · Selection sort · Bubble sort and the early-exit improvement · Insertion sort and nearly sorted data · Comparing the three2 LeetCode problems to practise22 min
- Lesson 17Merge SortSplit, sort the halves, merge — divide and conquer.Topics · Divide and conquer · Merging two sorted arrays · The recursion tree · Why it is O(n log n) · Extra space and stability · Counting inversions (preview)4 LeetCode problems to practise24 min
- Lesson 18Quick Sort, and When to Just Use .sort()Partitioning around a pivot, quickselect, and sorting numbers and objects correctly in JavaScript.Topics · Partitioning around a pivot · Quick sort and pivot choice · Worst case and how to avoid it · Quickselect for the k-th element · JavaScript's .sort(): the default text order and comparators · Sorting objects by a key7 LeetCode problems to practise26 min
Part 4 · Arrays and the First Patterns
Prefix sums, two pointers, sliding windows, Kadane's algorithm and matrices.
- Lesson 19Array Traversal ProblemsLargest and second largest, rotating, moving zeros, missing numbers and more — the problems every array round starts with.Topics · Largest and second largest · Checking if an array is sorted · Removing duplicates in place · Rotating by k (the reversal method) · Moving zeros · Missing number and single number · Union and intersection of sorted arrays7 LeetCode problems to practise22 min
- Lesson 20Prefix SumPre-compute running totals so that any range sum is instant.Topics · Running sums · Range sum queries · Pivot index · Prefix and suffix products · Subarray sum equals k (prefix sum + Map)7 LeetCode problems to practise24 min
- Lesson 21Two PointersTwo indices moving towards each other or in the same direction — pair sums, reversing, removing duplicates, 3Sum.Topics · Pointers from both ends · Pair sum in a sorted array · Same-direction pointers (read and write) · 3Sum · Container with most water · Three-way partition (Dutch national flag)8 LeetCode problems to practise26 min
- Lesson 22Sliding Window: Fixed SizeReuse the last window's work instead of recomputing it.Topics · From brute force to a sliding window · Maximum sum of k elements · Averages of every window · Counting with a window (vowels, matches)6 LeetCode problems to practise20 min
- Lesson 23Sliding Window: Variable SizeGrow and shrink a window to find the longest or shortest answer.Topics · The grow-and-shrink template · Longest window with a condition · Shortest window with a condition · “At most k” problems7 LeetCode problems to practise26 min
- Lesson 24Kadane's AlgorithmThe maximum subarray sum in a single pass, and the stock-trading problems built on the same idea.Topics · Maximum subarray: brute force to one pass · Returning the subarray itself · Best time to buy and sell stock · Maximum product subarray · Circular subarrays6 LeetCode problems to practise24 min
- Lesson 252-D Arrays and MatricesRows and columns: transpose, rotate, spiral order, set zeroes and search a matrix.Topics · Creating and looping over a matrix · Row and column sums · Transpose and rotate by 90° · Spiral order · Set matrix zeroes · Searching a sorted matrix7 LeetCode problems to practise26 min
Part 5 · Hashing Patterns
Two Sum, the “seen before?” technique, frequency maps and grouping.
- Lesson 26Two Sum and “Seen Before?”Trading memory for speed with a map of what you have already met.Topics · Two Sum three ways: brute force, sort + two pointers, Map · Duplicates within a distance k · Longest consecutive sequence · Counting subarrays with a Map6 LeetCode problems to practise22 min
- Lesson 27Frequency Maps and GroupingAnagrams, top frequencies, the majority element and grouping by a key.Topics · Designing a good key · Group anagrams · Top k frequent (bucket idea) · Majority element and Boyer–Moore voting · Isomorphic strings7 LeetCode problems to practise24 min
Part 6 · Binary Search
Halving a sorted array, then binary search on the answer.
- Lesson 28Binary Search on a Sorted ArrayHalve the search space every step; first and last positions; rotated arrays.Topics · The binary search template · Avoiding infinite loops and off-by-one · Lower bound and upper bound · First and last occurrence · Search insert position · Rotated sorted arrays7 LeetCode problems to practise26 min
- Lesson 29Binary Search on the AnswerWhen the answer itself can be searched: square roots, eating speeds, shipping capacity.Topics · Recognising a yes/no condition that flips once · Square root · Minimum speed and minimum capacity · Minimising the largest part6 LeetCode problems to practise24 min
Part 7 · Strings
Palindromes, reversing, counting and substring windows.
- Lesson 30String PatternsPalindromes, reversing words, common prefixes, Roman numerals and compression.Topics · Palindromes: two pointers and expand around the centre · Longest common prefix · Roman numerals · String compression · Rotation check5 LeetCode problems to practiseread
- Lesson 31Substrings and WindowsUse a sliding window on text: no repeated letters, replacing characters, anagrams and the smallest window.Topics · Longest substring without repeating characters · Longest repeating character replacement · Permutation in a string · Find all anagrams · Minimum window substring5 LeetCode problems to practiseread
Part 8 · Recursion and Backtracking
Recursion trees, subsets, permutations and standard backtracking problems.
- Lesson 32Recursion TreesDraw every call as a tree, so recursion is easy to follow.Topics · Drawing a recursion tree · Parameter-based vs return-based recursion · Multiple recursive calls · Fast power with recursion · The cost of recursion (preview of memoisation)3 LeetCode problems to practiseread
- Lesson 33Subsets and PermutationsPick or skip each item, to list every possible choice.Topics · The pick / skip decision · All subsets · Subsets with duplicates · Permutations · Combinations of size k · Letter combinations of a phone number5 LeetCode problems to practiseread
- Lesson 34BacktrackingChoose, try, then undo. Examples: combination sum, N-Queens, word search.Topics · The choose–explore–undo template · Combination sum · Palindrome partitioning · Word search in a grid · N-Queens5 LeetCode problems to practiseread
Part 9 · Linked Lists
Build one, reverse it, and the fast/slow pointer pattern.
- Lesson 35Building a Linked ListNodes and pointers (links to the next node), built from scratch.Topics · Nodes and the next pointer · Traversal and length · Insert at head, tail and position · Delete a node · Doubly linked lists · Arrays vs linked lists3 LeetCode problems to practiseread
- Lesson 36Reverse and Fast/Slow PointersReverse a list, find the middle, and check if the list has a loop (a cycle).Topics · Reverse a list (iterative and recursive) · Middle of a list · Detect a cycle (Floyd's algorithm) · Palindrome linked list · Reverse part of a list5 LeetCode problems to practiseread
- Lesson 37Merging and Cycle ProblemsJoin sorted lists, find where a loop starts, and remove the nth node from the end.Topics · Dummy head nodes · Merge two sorted lists · Start of a cycle · Remove the nth node from the end · Intersection of two lists · Add two numbers · Reorder and sort a list6 LeetCode problems to practiseread
Part 10 · Stacks and Queues
Valid parentheses, queues, deques and the monotonic stack.
- Lesson 38StacksLast in, first out. Examples: valid brackets, a stack that knows its minimum, and working out expressions.Topics · Stack operations with an array · Valid parentheses · Min stack · Evaluating postfix expressions · Decoding nested strings5 LeetCode problems to practiseread
- Lesson 39Queues and DequesFirst in, first out, and a queue you can use from both ends.Topics · Queue operations, and why shift() is slow · Queue using two stacks · Circular queue · Deque · Sliding window maximum with a deque4 LeetCode problems to practiseread
- Lesson 40Monotonic StackFind the next bigger item. It also solves temperatures, stock spans, histograms and rain water.Topics · Next greater and next smaller element · Circular arrays · Daily temperatures · Stock span · Largest rectangle in a histogram · Trapping rain water6 LeetCode problems to practiseread
Part 11 · Trees
Traversals, BFS and DFS on trees, binary search trees, LCA.
- Lesson 41Binary Trees and TraversalsRoot, leaves and height. Preorder, inorder and postorder, drawn and coded.Topics · Tree vocabulary · Building nodes in JavaScript · Preorder, inorder and postorder (recursive) · Iterative traversals with a stack · Maximum depth, same tree, invert a tree5 LeetCode problems to practiseread
- Lesson 42Level Order (BFS) on TreesVisit a tree one layer at a time with a queue.Topics · Level order with a queue · Processing one level at a time · Right side view · Zigzag order · Minimum depth4 LeetCode problems to practiseread
- Lesson 43DFS on TreesHeight, balance, diameter (the longest path) and path sums.Topics · Returning values up the tree · Balanced tree · Diameter · Path sum · Maximum path sum · Symmetric tree and subtree5 LeetCode problems to practiseread
- Lesson 44Binary Search TreesSearch, insert, delete, check a tree is valid, and find the k-th smallest value.Topics · The BST property · Search and insert · Delete · Validate a BST · K-th smallest with inorder · Build a BST from a sorted array5 LeetCode problems to practiseread
- Lesson 45Lowest Common Ancestor and Building TreesFind the lowest common ancestor in a binary tree and a BST. Build a tree again from its traversals.Topics · LCA in a binary tree · LCA in a BST · Build a tree from preorder and inorder · Serialise and deserialise a tree4 LeetCode problems to practiseread
Part 12 · Heaps, Greedy and Intervals
Top-K with heaps, greedy choices and interval merging.
- Lesson 46Heaps and Top-KBuild a priority queue by hand in JavaScript, then use it to find the top K items.Topics · The heap property and its array form · Push and pop: sift up and sift down · Writing a MinHeap in JavaScript · K-th largest and top k frequent · Merge k sorted lists · Median of a data stream6 LeetCode problems to practiseread
- Lesson 47Greedy AlgorithmsWhen the best choice right now is also the best choice overall, and how to tell.Topics · What makes a problem greedy · Assigning cookies and making change · Jump game · Gas station · Choosing non-overlapping activities5 LeetCode problems to practiseread
- Lesson 48Interval ProblemsSort by start time, then merge, insert and count overlapping intervals.Topics · Sorting intervals · Merge intervals · Insert an interval · Remove the fewest intervals · Minimum arrows and meeting rooms4 LeetCode problems to practiseread
Part 13 · Graphs
Storing graphs, BFS/DFS, topological sort, shortest paths, union-find.
- Lesson 49What a Graph IsVertices, edges and the adjacency list (each vertex's list of neighbours).Topics · Vertices and edges; directed and undirected; weighted · Adjacency list vs adjacency matrix · Building a graph from an edge list · Degree, paths and connected components · Grids as graphs2 LeetCode problems to practiseread
- Lesson 50Graph Traversal: BFS and DFSCount islands, flood fill, rotting oranges and copy a graph.Topics · BFS with a queue and a visited set · DFS, recursive and with a stack · Connected components · Grid traversal: islands and flood fill · Multi-source BFS · Cloning a graph5 LeetCode problems to practiseread
- Lesson 51Topological SortPut tasks in order when some depend on others, and find loops (cycles).Topics · Directed acyclic graphs · Kahn's algorithm (in-degree) · DFS-based ordering · Cycle detection in directed graphs · Course schedule2 LeetCode problems to practiseread
- Lesson 52Shortest PathsBFS when all steps cost the same, Dijkstra for other costs, and Bellman–Ford for limits.Topics · BFS for unweighted graphs · Dijkstra with a priority queue · Shortest paths on a grid · Bellman–Ford and limited stops4 LeetCode problems to practiseread
- Lesson 53Union-FindGroup things fast: connected groups, finding cycles and minimum spanning trees.Topics · Parent array and find · Path compression · Union by size or rank · Connected components and redundant edges · Kruskal's minimum spanning tree4 LeetCode problems to practiseread
Part 14 · Dynamic Programming
From recursion to memoisation, then 1-D, 2-D and string DP.
- Lesson 54Dynamic Programming From RecursionRepeated subproblems, memoisation, tabulation and saving memory.Topics · Overlapping subproblems and optimal substructure · Memoisation (top-down) · Tabulation (bottom-up) · Reducing space · Climbing stairs and minimum cost3 LeetCode problems to practiseread
- Lesson 551-D Dynamic ProgrammingHouse robber, coin change, decode ways, word break and the longest increasing subsequence.Topics · Defining the state · House robber I and II · Coin change · Decode ways · Word break · Longest increasing subsequence6 LeetCode problems to practiseread
- Lesson 562-D Dynamic ProgrammingPaths on a grid and the 0/1 knapsack problems.Topics · Grid paths · Paths with obstacles and minimum path sum · 0/1 knapsack · Partition equal subset sum · Unbounded knapsack: coin change II5 LeetCode problems to practiseread
- Lesson 57DP on StringsLongest common subsequence, edit distance and the longest palindrome inside a string.Topics · Longest common subsequence · Edit distance · Longest palindromic subsequence · LIS in O(n log n) with binary search4 LeetCode problems to practiseread
Part 15 · Extras and the Interview
Tries, bit tricks, the interview playbook and a revision plan.
- Lesson 58Tries and Bit ManipulationPrefix trees, and the bit tricks that interviews ask about.Topics · Trie: insert, search, startsWith · Word dictionary with wildcards · Bitwise operators: &, |, ^, <<, >> · Checking and counting set bits · Power of two and the single number · Subsets with bitmasks5 LeetCode problems to practiseread
- Lesson 59The Interview PlaybookAsk, plan, code, test: the 45 minutes, step by step.Topics · Clarifying questions · Examples and edge cases out loud · Brute force, then optimise · Writing clean code when time is short · Testing with a dry run · Stating time and space complexity · Using hints well · JavaScript-specific tipsread
- Lesson 60Your Revision PlanA cheat sheet to spot patterns, a week-by-week plan and a checklist to test your memory.Topics · Spot the pattern: from the words of the problem to the technique · A week-by-week practice plan · Spaced repetition for problems · Mock interviewsread
Glossary
162 terms — dry run, accumulator, off-by-one, frequency map and the rest. Inside any lesson, hover or tap a dotted term to see its meaning without leaving the page. Browse all terms →
How this syllabus was built
The order of topics and the subtopics in every lesson were checked against the most widely used free resources for learning DSA and preparing for interviews. They are all worth bookmarking.
| Resource | What it is best for |
|---|---|
| coding-interview-university (362k ★) | A complete computer-science study plan; good for seeing the whole field. |
| javascript-algorithms (197k ★) | Every standard data structure and algorithm written in JavaScript, with explanations. |
| Tech Interview Handbook (143k ★) | Per-topic cheat sheets: techniques, edge cases and the essential questions. Also home of the Grind 75 list. |
| labuladong's algorithm notes (136k ★) | Reusable templates for problem families such as sliding window and binary search. |
| Hello Algo (130k ★) | A free, animated book for beginners; excellent pictures of every data structure. |
| NeetCode roadmap | A pattern-by-pattern problem list (NeetCode 150) with a video solution for each problem. |
| Striver's A2Z DSA sheet | A long, step-by-step problem sheet that starts from the absolute basics. |
| LeetCode | Where you practise. Every lesson links the matching LeetCode problems. |
| VisuAlgo | Interactive animations of sorting, trees, graphs and more. |
GitHub star counts as of October 2026.