Sign In
You are coding as a Guest. Sign in with your RoleNest account to permanently track your streak, earn XP, and climb the Campus Leaderboard!
Sign In with RoleNest
🔥Capacity To Ship Packages Within D Days: Binary Search AnswerMedium
DAILY PROBLEM OF THE DAY+50 XP • Daily Streak

Solve today's challenge or tackle one of the 3 Super Hard challenges for +150 XP.

MediumBinary Search•Acceptance: 69.5%

Capacity To Ship Packages Within D Days: Binary Search Answer

Targeted in FAANG & Tech OA:GoogleAmazonSwiggy
Real-World Engineering Context
Directly powers logistics batch truck dispatching at Amazon and Delhivery to minimize fleet fuel capacity overhead.
A conveyor belt has packages that must be shipped from one port to another within `days` days. The `i`th package on the conveyor belt has a weight of `weights[i]`. Each day, we load the ship with packages on the conveyor belt (in the order given by `weights`). We may not load more weight than the maximum weight capacity of the ship. Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within `days` days.

Sample Test Cases

Input: [[1,2,3,4,5,6,7,8,9,10],5]
Expected: 15
Input: [[3,2,2,4,1,4],3]
Expected: 6
Input: [[1,2,3,1,1],1]
Expected: 8

Constraints

  • 1 <= days <= weights.length <= 5 * 10^4
  • 1 <= weights[i] <= 500
Recruiter Fast-Track ReferralVerified Candidate
Direct pipeline to Google, Amazon, Microsoft, Swiggy, & Uber recruiters
DevScore: 750/1000

Top DevScore profiles bypass resume screening filters. Every verified problem solve writes authentic proof-of-work to your profile and dispatches you directly into employer inboxes on RoleNest.