← back to unit
Challenge
# sorting advanced
Balanced Backpacks
Two hikers split the gear: heaviest item to hiker A, next to hiker B, next to A… taking turns down the sorted pile. 🎒
You get the gear weights. Deal them out that way and print A's total and B's total, separated by a space.
Example:
Input: weights = [8, 5, 3, 2]
Output: 11 7
Sorted heaviest-first gives [8, 5, 3, 2]. Alternating deals 8 and 3 to hiker A (8+3=11) and 5 and 2 to hiker B (5+2=7).
💡 need a hint?
sort-balanced-backpacks.py🔒 given lines are locked — write your code in between
loading...