Twenty billion checks
transcript
A nightly job reads two hundred thousand ids. It flags any id that appears twice. Your first version checks every pair. Does it fit a two second budget?
Two hundred thousand ids make a lot of pairs. The count is n times n minus one, over two. That is almost twenty billion checks. You did not run anything. You counted.
The machine does about a hundred million steps a second. Divide twenty billion by a hundred million. The answer is about two hundred seconds. That is three minutes and twenty seconds.
The budget is two seconds. The job needs two hundred. It is a hundred times too slow. You know this before you ship.
The loop stops at the first match. That helps only when a duplicate exists. With no duplicate, it makes every check. Plan for the worst case.
Counting told you the problem. It did not run the job once. A better method needs fewer checks. Later lessons give you those methods.
Count first. Then ship. Full breakdown in the lecture.