Correct code. Twelve seconds per truck.
transcript
This code is correct. It still fails the dispatch screen. Let us count why.
A truck has 37 kilograms of room. Find two waiting parcels that fill it exactly. Here, 11 and 26 work.
The first attempt tries every pair. Take each parcel. Try every heavier partner. Stop when two parcels fill the truck exactly. For seven parcels, that is 14 checks. Instant.
Now a central hub at the evening peak. It holds up to 50,000 waiting parcels. That is about one point two five billion pairs. When no pair fits, it checks every one. At a hundred million checks a second, that is twelve seconds.
The screen must answer within one second. And a truck leaves every few minutes. So the first attempt is twelve times too slow.
Here is the clue. The list is sorted by weight. The first attempt never uses that. Sorted data lets one check rule out a whole parcel.
Full breakdown in the lecture.