Guess the Big O: 15 levels reading code and picking O(1), O(n), O(log n) or O(n²). An algorithm complexity game for insight into code performance.
Big O measures how fast the number of steps grows as the input gets bigger. O(1) = constant (always 1 step). O(n) = grows linearly. This race shows the difference.
Nested loops produce O(n²). Every outer turn triggers n inner turns. For n = 100 → 10,000 steps. For n = 1000 → 1 million steps. It grows very fast.
O(log n) appears when the problem is halved every step. An array of 1 million items → only 20 steps of binary search.
Beware of "cheap" operations that are really linear: .includes(), .indexOf(), .find() are all O(n). Used inside a loop = O(n²). Set/Map = O(1) lookup.
O(2ⁿ) = exponential. Every call branches in two. fib(40) without a memo = hundreds of millions of calls. Memoization (storing results) cuts the recomputation → O(n). A key technique in dynamic programming.
Big O hides constants. O(2n) and O(n) are both written O(n). But in practice the constant still matters: 2n is slower than n. Combine loops when you can.
And more, 15 levels in all.