Blog

Fundamentals

Time Complexity & Big-O for Interviews — Explained Simply

6 min readUpdated

"What's the time complexity?" is the most predictable follow-up in any coding interview, and freezing on it can sink an otherwise-correct solution. The good news: you don't need heavy math. You need to recognise a handful of shapes and reason out loud. Here's the practical version.

Big-O describes how your runtime grows as the input grows — not the exact time. Interviewers care that you can estimate it and talk through the trade-off, not that you memorised a proof.

The complexities you'll actually see

Big-ONameTypical source
O(1)ConstantHash-map lookup, array index
O(log n)LogarithmicBinary search, balanced-tree ops
O(n)LinearOne pass over the input
O(n log n)LinearithmicGood sorting, divide-and-conquer
O(n²)QuadraticNested loops over the same input
O(2ⁿ)ExponentialNaive recursion / subsets / brute force

How to analyse on the spot

  • Count the loops. One pass = O(n). A loop inside a loop over the same data = O(n²).
  • Halving = log. If each step cuts the problem in half (binary search), that's O(log n).
  • Recursion = branches^depth. Two recursive calls per level, n levels deep, tends toward O(2ⁿ) unless you memoise.
  • Don't forget space. An extra hash map or recursion stack is O(n) space — interviewers ask about both.

What interviewers actually want

State your complexity, then say why ("it's O(n) because I do a single pass and the hash-map lookups are O(1)"). If your brute force is O(n²), name it and mention the better approach even if you don't code it — showing you see the optimisation often matters as much as writing it.

Complexity is the language tying every pattern together — and the DSA patterns cheat sheet shows which patterns hit which complexity. Avoid the usual slip-ups in common coding interview mistakes, and when you're ready to practise by role, DSA Tracker orders the right problems first.

Keep reading

Product

Company-Wise DSA Sheets — Built From Verified Tags, Not Guesses

Company-tagged problem lists are everywhere — and most of them are copied from each other with no source. Ours ship with a receipt: every tag comes from the problem's own GeeksforGeeks page, fetched and recorded with a timestamp.

5 min read
Guide

DSA for the Amazon SDE Interview — A Deep, Specific Guide

Amazon is the most predictable big-tech loop a fresher can prepare for — but only if you know its actual lean: grids and graphs over exotic DP, a debugging section in the OA, and Leadership Principles that quietly decide SDE-1 offers. Here's the deep, Amazon-only plan.

7 min read