ALGORITHMS
Algorithm Notebook
Classic interview problems, each worked through in plain JavaScript. Open one and hit submit to run it — the input array is shown on the page.
Binary Search
Find a key in a sorted array by halving the search space each step. Type a number and see whether it's there.
RunHeap Sort
Build a max-heap, then repeatedly swap the root to the end and sift down to produce a sorted array in place.
RunTrapping Rain Water
Given an elevation map of unit-width bars, compute how much water is trapped between them after rain.
RunRepeating Numbers
Pull out every value that appears more than once in an array, without sorting it first.
RunPairwise Swap
Turn [1,2,3,4,…] into
[2,1,4,3,…] by swapping adjacent pairs — including
the odd-length edge case.