Ctrl K

Pass the Load to the Left

Medium
Servers stand in a row, and loads[i] is the number of jobs on server i. In one step you may take one job from server i (where i ≥ 1 and loads[i] > 0) and hand it to its left neighbour, server i − 1. You may take any number of steps. Return the smallest possible value of the largest load in the row.
Example 1
loads=[2, 8, 0, 6] → 5

Move 3 units from position 1 to position 0: [5, 5, 0, 6]. Then 1 unit from position 3 to position 2: [5, 5, 1, 5]. The maximum is 5, and it cannot go lower because the first two positions hold 10 together.

Example 2
loads=[9, 2, 4] → 9

Load only moves left, and position 0 already holds 9, which can never decrease.

Example 3
loads=[0, 0, 7] → 3
Constraints
  • 2 ≤ len(loads) ≤ 10⁵
  • 0 ≤ loads[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Heaviest Reading Day HardEven Out With Increments MediumRug Over Painted Stretches MediumRichest Row of Houses MediumShift a Segment to Match Medium
loading Python…
Input
loads=[2, 8, 0, 6]
Expected
5

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