bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1011. Capacity To Ship Packages Within D Days

1011. Capacity To Ship Packages Within D Days

Leetcode Solutions

Key approach of the solution: Binary Search

  1. Initialize left to the maximum weight in weights and right to the sum of all weights in weights.
  2. While left is less than right: a. Calculate mid as the average of left and right. b. Check if it's possible to ship all packages within days using mid as the ship's capacity. c. If it is possible, set right to mid. d. If it is not possible, set left to mid + 1.
  3. Return left as the minimum capacity required.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...