Ctrl K

The Heaviest Sack

Medium
A warehouse holds sacks of grain: sacks[i] is the weight of sack i in kilograms. At most splits times you may take any sack and pour it into two new sacks, each holding a positive whole number of kilograms (a 5 kg sack, say, can become 1 and 4 or 2 and 3). The movers complain about the heaviest sack. Return the smallest possible weight of the heaviest sack after the splits.
Example 1
sacks=[10], splits=3 → 3

Three splits give four sacks, for example 3, 3, 2, 2, so the heaviest weighs 3. Less is impossible: four sacks of 2 hold only 8.

Example 2
sacks=[7, 3, 5], splits=2 → 4

Split 7 into 4 and 3 and split 5 into 4 and 1: the sacks are 4, 3, 3, 4, 1. Getting the maximum down to 3 would take three splits.

Example 3
sacks=[2, 6, 1], splits=10 → 1
Constraints
  • 1 ≤ len(sacks) ≤ 10⁵
  • 1 ≤ sacks[i] ≤ 10⁹
  • 1 ≤ splits ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFind in a Shifted Sorted Array MediumFirst and Last Copy MediumFind in a Row-Chained Grid MediumFind in a Shifted Array With Repeats MediumMinimum of a Shifted List Medium
loading Python…
Input
sacks=[10], splits=3
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.