#187MediumDynamic Programming· Subset Sum (0/1 Knapsack)
Split Shifts Evenly
Input format
`minutes`: an array of positive integers.
Output format
`true` if the tasks can be divided into two groups with equal total minutes, otherwise `false`.
Examples
Input: minutes = [1, 5, 11, 5]
Output: true
The total is 22. One nurse takes 11 and the other takes 1 + 5 + 5 = 11.
Input: minutes = [1, 2, 3, 5]
Output: false
The total is 11, which is odd, so an equal split is impossible.
Input: minutes = [3, 3, 3, 4, 5]
Output: true
The total is 18; the subset 4 + 5 = 9 (and the rest 3 + 3 + 3 = 9) works.
Constraints
- 1 <= minutes.length <= 200
- 1 <= minutes[i] <= 100
- #dynamic-programming
- #knapsack
- #subset-sum
- #bitset