Fix one. Search for two.
transcript
Three values must add up to a target. Do not search for three at once. Fix one. Search for two.
Sort the lengths first. Fix the first value, one minute. Left starts after it. Right starts at the end. The values after it are the pair to search.
Add the three values. Too small? Move left. Too large? Move right. Equal? Record it. The other pointer stays where it is. Then add the three values again.
The list is sorted. A smaller right cannot fix a small total. So each move rules one value out. No total is ever checked twice. Nothing useful is skipped.
There are n first values. Each pair search takes at most n moves. So it is order n squared, not n cubed. Three thousand tracks need under ten million steps. The loops needed four and a half billion.
Three thousand tracks take under ten million steps. Full breakdown in the lecture.