Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

64. Capacity To Ship Packages Within D Days

MediumDay 19 of 60Binary Search

Packages with weights weights[i] sit on a conveyor belt and must be shipped in the given order within days days. Each day the ship is loaded with consecutive packages from the front of the belt, as long as their total does not exceed the ship's capacity. Return the smallest capacity that ships everything within days days.

Example 1
Input: weights = [1,2,3,4,5,6,7,8,9,10], days = 5
Output: 15
Days: [1,2,3,4,5], [6,7], [8], [9], [10].
Example 2
Input: weights = [3,2,2,4,1,4], days = 3
Output: 6
Days: [3,2], [2,4], [1,4].
Constraints
  • 1 <= days <= weights.length <= 5 * 10^4
  • 1 <= weights[i] <= 500
Hints
Frequently asked at: Amazon, Google, Flipkart
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min