Skip to content
Onsite

Masai Packers and Movers II

MediumP3Coding

You must move exactly k units of weight. The company has trucks with capacities caps[i]. A truck is only allowed to travel when it is completely full, so it carries exactly its capacity. Only one truck travels per day, and a truck may be used on as many days as you like.

Return [fewest, most]: the minimum and the maximum number of days over all ways to carry exactly k units. If it is impossible, return [-1].

Example 1

Input
k = 10, caps = [2,3,5]
Output
[2,5]
Why
Fewest: 2 days (5 + 5). Most: 5 days (2 * 5).

Example 2

Input
k = 7, caps = [2,4]
Output
[-1]
Why
No combination of 2s and 4s makes an odd total.

Example 3

Input
k = 1, caps = [1]
Output
[1,1]

Constraints

  • 1 <= k <= 10^4
  • 1 <= caps.length <= 20
  • 1 <= caps[i] <= 100

Hints

Run checks the 3 visible tests, Submit all 10.