Gamified challenge · Binary search on the answer
Crates weights[0], weights[1], … wait on the dock in that order. Each day one ship sails, loaded with the next crates in the queue as long as their total stays within its capacity; crates can't be split or reordered. Everything must ship within d days.
Write minCapacity(weights, d) that returns the smallest ship capacity that clears the dock in at most d days.
Example: weights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], d = 5. Capacity 15 works: [1, 2, 3, 4, 5], [6, 7], [8], [9], [10]. Capacity 14 would need 6 days, so the answer is 15.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google