← Back to courses
Data Structures & Algorithms
Problems grouped by technique · Interactive step-through visualizers · Editable JavaScript solutions
01Arrays & Hashing- Trade memory for speed: keeping what you have seen in a map or set means a lookup is one step instead of another pass over the data
Two SumEasy
Find the indices of two numbers that add up to a target.
need = target - num
seen need? -> answer
else remember num -> index
Time O(n) · Space O(n)
Longest Consecutive SequenceMedium
Length of the longest run of consecutive numbers, in a single pass.
set = new Set(nums)
num - 1 in set? skip
else count num, num+1, ...
Time O(n) · Space O(n)
02Two Pointers- Two positions moving through the data replace a loop inside a loop - usually once the data is sorted
Remove Duplicates from Sorted ArrayEasy
Squeeze a sorted array so each value appears once, reusing the same array rather than building a new one.
read scans every value
k marks the next free slot
new value? nums[k++] = it
Time O(n) · Space O(1)
3SumMedium
All unique triplets that sum to zero.
sort
fix nums[i], then L and R
sum < 0 -> L++; > 0 -> R--
Time O(n²) · Space O(1) beyond sorting
Trapping Rain WaterHard
How much water an elevation map holds after rain.
water = min(leftMax, rightMax) - h
lower side is the limit
move the lower pointer
Time O(n) · Space O(1)
03Sliding Window- Slide a stretch of the input along, growing and shrinking it, instead of re-checking every possible stretch from scratch
Best Time to Buy and Sell StockEasy
Maximum profit from one buy followed by one later sell.
minPrice = cheapest so far
profit = price - minPrice
best = max(best, profit)
Time O(n) · Space O(1)
Longest Substring Without Repeating CharactersMedium
Length of the longest substring with all-distinct characters.
R extends the window
repeat inside it? L = lastSeen + 1
best = max(best, R - L + 1)
Time O(n) · Space O(min(n, charset))
04Stack- Last in, first out: the most recent thing you opened is the first thing that has to close
05Linked List & Design- Put two data structures together so that every operation stays fast
06Binary Search- Cut the range you are searching in half at every step, when the answer sits somewhere in a sorted range
07Recursion- Structures that contain themselves: solve the smallest case directly, then trust the same function to handle each smaller part
Learn the technique, not the problem. Each group is a pattern that transfers: once two pointers clicks on 3Sum, it is the same move on any sorted-array question.