Loading...
Loading...
Loading...
A courier can carry two parcels if their weights add up to less than a limit. Count the pairs of parcels (different positions in the list) whose total weight is less than the limit.
Example
Input
40 10 25 5 30 45
Output
5
Pairs: 5+10, 5+25, 5+30, 10+25, 10+30.
Try the problem first. Open one hint at a time.
Sort the weights first. After sorting, two pointers can count many pairs at once.
If the smallest and the largest at the pointers fit, then the smallest also fits with every weight between them.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor