After stating an O(n^2) baseline, how do you answer the follow-up 'what gap are you trying to close'?
answer
- the gap has two ends, not one
- what must any correct answer read?
- what shape is the required output?
- a comparison-based full ordering has a known floor
- then ask how big the input really gets
basics
~20 sName a defensible target: reading every record floors you at linear, and a comparison-based full ordering at n log n. State the gap from your quadratic baseline to that floor, then whether the real input size makes closing it worth anything.
solid answer
~50 sThe gap is the distance between the baseline I just stated and a target I can defend, so I answer in three parts. First the floor: any correct answer has to look at every score record at least once, so nothing beats linear, and if I must produce a full ranking by comparing scores, that pushes the realistic floor to n log n. Second the gap: I stated all-pairs comparison at O(n^2), so I am trying to close quadratic down to about n log n, roughly a factor of n / log n. Third, whether it matters: for a few hundred players refreshed hourly, quadratic is tens of thousands of comparisons and I would not spend the complexity budget; for millions of records a minute it is fatal. Naming a target without a reason it is reachable is the answer interviewers discount.
go deeper
Be ready to say what any correct solution must at minimum do — read every item — and use that as the floor. Getting the phrase 'we have to look at everything, so nothing beats linear' out loud already answers most of the question.
Explain both bounds and where each comes from: reading the input, and the shape of the required output. State the gap as a ratio rather than two loose symbols, and be precise about when a comparison-based floor does and does not apply.
Show that you close the loop on real numbers: ask for the input size and refresh rate, do the arithmetic aloud, and be willing to conclude that the baseline stands. Sizing the prize before chasing it is the judgment being tested.
Own the decision framing: an asymptotic gap is a hypothesis about future load, and closing it buys headroom at the price of a harder-to-maintain implementation. Be able to say what growth evidence would justify spending that budget now rather than later.
## What the question is really asking When an interviewer hears your baseline and asks "what gap are you trying to close?", they are not asking you to produce the optimized algorithm. They are testing whether you can reason about *how much room there is* before you go looking for it. The gap is the distance between a stated baseline and a defensible target, and a good answer names both ends plus a reason the target is plausible. Take a leaderboard: rank players by score, and the baseline compares every player's score record against every other, O(n^2) time. ## Where the floor comes from There are two grounded arguments a candidate can make out loud, and they are both cheap. **The input-reading bound.** Any correct answer must at minimum look at every record — if you skip one, an adversary puts the top score there. So Ω(n) is a hard floor on time for this problem. That single sentence kills the most common bad answer, "I will get it to O(log n)", which promises to rank players without reading all their scores. **The output-shape bound.** If the required output is a full ordering of all n players, and the only thing you may do with two scores is compare them, then you are sorting, and comparison sorting has an Ω(n log n) lower bound. So the realistic floor is n log n for a full ranking, and the gap from the baseline is n^2 down to n log n — a factor of about n / log n, which at a million records is a five-order-of-magnitude difference rather than a tidy-up. Both bounds move with the *requirement*, which is why stating them makes you sound like you understand the problem rather than the algorithm. If the requirement is only the top few players rather than a full ranking, the output no longer has n items, the sorting argument no longer applies, and the floor drops back toward linear. If scores are small bounded integers rather than opaque values you can only compare, the comparison lower bound does not bind either — counting-style approaches escape Ω(n log n) precisely because they never compare two scores. Saying "n log n *if I rank by comparison*" is the precise version; saying "n log n, always" overstates a real theorem. ## The third part: does the gap matter? This is the half that separates a candidate who recites bounds from one who has shipped something. A gap is only worth closing if the input reaches the size where it hurts. Spell out the arithmetic aloud. Two hundred players, all-pairs comparison: about twenty thousand comparisons, microseconds, refreshed hourly. Closing that gap buys nothing and costs you a more complex implementation to maintain. Five million score events per minute: the quadratic pass is on the order of 10^13 comparisons and simply does not finish. Same asymptotic gap, opposite decisions. So the strong answer ends with a question back: "How many players, and how often does the ranking refresh?" Interviewers usually have those numbers ready, and asking shows you know that asymptotics alone do not decide anything. If they say the input is small, the correct engineering answer may genuinely be "then the baseline is my solution" — though in an interview you should still be ready to show the improvement if asked, because they may be probing the technique regardless of the constraint. ## Common failure modes **Naming a target with no justification.** "I think we can do it in O(n)" invites an immediate "how?" and if you have nothing, you have spent credibility. Better: "the floor is linear because we must read everything; whether linear is reachable depends on whether a full ordering is required." **Claiming a target below the input-reading bound.** Sub-linear answers require not reading the whole input, which for a full ranking is impossible. This is the single most detectable error in the answer. **Assuming every gap must be closed.** Interviewers do ask questions where the honest answer is that the baseline is adequate, and they are watching to see whether you notice. **Confusing the gap with the technique.** The gap is a pair of numbers and a reason. Which structure or precomputation actually closes it is a separate step, and answering the gap question by jumping straight into an implementation sketch skips the part being assessed. ## The shape of a complete answer One sentence naming the floor and why it holds. One sentence naming the gap as a ratio, so the size of the prize is explicit. One sentence tying it to the real input bounds, ideally ending in a question about them. Thirty seconds, and you have shown you can size an optimization before attempting it — which is exactly the skill that stops engineers from spending a week making something asymptotically elegant and operationally identical.
- You say the floor for a full ranking is n log n. When is that claim wrong?When the ranking is not produced by comparing scores. The Ω(n log n) bound applies to comparison-based sorting only; with small bounded integer scores, counting-style approaches sort in linear time because they never compare two values. It is also wrong if the requirement is only the top few players rather than a full ordering.
- The interviewer says there will only ever be about three hundred players. Now what?Say plainly that the quadratic baseline is roughly forty-five thousand comparisons, which is negligible, so the gap is real but not worth the added complexity at this size. Then offer to show the faster approach anyway, since they may be probing the technique rather than the deployment decision.
- Why is 'I'll get it down to O(log n)' a bad answer for a full ranking?It promises to produce a correct ranking without reading every score record. Any record you never look at could hold the top score, so the target sits below the hard input-reading floor of Ω(n). Naming an impossible target costs more credibility than naming no target at all.
saying these in an interview costs you the question
- Names a target faster than reading the whole input
- Says 'we can definitely do better' with no target at all
- Claims n log n is a floor even for non-comparison ranking
- Assumes every asymptotic gap is worth closing
- Never asks how large the input actually gets
- Answers with an implementation sketch instead of a bound