#330 · Dynamic programming · Intermediate · 80 XP · about 15 min
Two friends are carrying a pile of parcels home, and weights lists how heavy each parcel is. They want to share the parcels so that both carry exactly the same total weight. Every parcel must be carried by one of them, and no parcel can be split.
Write can_split_evenly(weights) that returns True if such a fair split exists and False otherwise.
can_split_evenly([3, 1, 4, 2]) # returns True can_split_evenly([7, 3, 2, 2]) # returns True can_split_evenly([2, 5, 9]) # returns False
The first pile splits as 3 + 2 and 1 + 4. In the last one the total is 16, but no group of parcels weighs exactly 8.
1 <= len(weights) <= 2001 <= weights[i] <= 100First solves only, ranked by stars and then time.