The author spent days thinking about it, whereas sorting is the immediate obvious answer. Developer time is massively more valuable than computer time by a factor of 1000
And the clever approach only works on data that is perfect, and that’s extremely rare in the real world
Real world requirements usually contain inaccurate assumptions. He spent days to find a terrible answer, when the obvious solution is much better