📐 DSA

Big-O Notation Explained Like You're Five

📅 Jun 26, 2026 ⏱ 4 min read

Big-O answers one question: when the input gets 10x bigger, how much slower does your code get?

The ladder (best → worst)

Reading your own code

for (const x of arr)          // O(n)
  for (const y of arr)        //   × O(n)  = O(n²)

for (const x of arr) { ... }  // O(n)
for (const y of arr) { ... }  // + O(n)   = O(n) — sequential adds, nested multiplies

The classic upgrade

Two Sum brute force = nested loops O(n²). With a hashmap: one loop, O(1) lookups → O(n). This exact upgrade is what interviewers wait for — solve it on our judge.

Rules: drop constants (O(2n)=O(n)), keep the dominant term (O(n²+n)=O(n²)).

← All Articles