Dodomeki
Sign in

133. The Route's Minimum Capacity

Medium

A truck must deliver every package on a route within dias days. The packages are queued and must be loaded in this order: each day, the truck carries a consecutive segment of the queue without exceeding its capacity. It may end the day before reaching capacity, but it cannot split a package across days.

Find the smallest integer capacity that allows all packages to be delivered within dias days. Return that capacity.

Example 1
Input: pesos = [1,2,3,4,5,6,7,8,9,10], dias = 5
Output: 15
Explanation: With capacity 15, the deliveries can be completed in five days, and no smaller capacity is sufficient.
Example 2
Input: pesos = [3,2,2,4,1,4], dias = 3
Output: 6
Explanation: One possible division across three days has loads 5, 6, and 5.
Example 3
Input: pesos = [7,7,7], dias = 5
Output: 7
Explanation: Each package can be carried on its own day without exceeding capacity 7.
Constraints
  • 1 <= pesos.length <= 10^5
  • 1 <= pesos[i] <= 10^4
  • 1 <= dias <= 10^5
Binary searchGreedy
Caso 1
pesos =
[1,2,3,4,5,6,7,8,9,10]
dias =
5
Expected =
15
Caso 2
pesos =
[3,2,2,4,1,4]
dias =
3
Expected =
6
Caso 3
pesos =
[7,7,7]
dias =
5
Expected =
7

Run checks these 3 cases. Submit runs all 12, including hidden ones.