Ctrl K

The Shuttle Robot

Hard
There are n cells in a row, numbered 0 to n - 1, and each cell has a score that starts at zero. A robot stands to the left of the row, just before cell 0 (think of it as position -1). The robot makes at most moves moves. Each move takes it one cell left or right, and the cell i it lands on adds gains[i] to its score. After the first move the robot must stay inside the row. Return the largest possible value of the smallest score among all cells.
Example 1
gains=[3, 5], moves=3 → 5

Moves: into cell 0 (scores [3, 0]), to cell 1 ([3, 5]), back to 0 ([6, 5]). The minimum is 5.

Example 2
gains=[4, 1, 2], moves=2 → 0

Two moves are not enough to reach cell 2, so its score stays 0.

Example 3
gains=[2, 3, 1], moves=7 → 2
Constraints
  • 2 ≤ n = len(gains) ≤ 5 · 10⁴
  • 1 ≤ gains[i] ≤ 10⁶
  • 1 ≤ moves ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Heaviest Reading Day HardTrim Down to a Hill HardFewest Inserts to Reveal a Pattern HardLifters and Energy Drinks HardKeep Every Lamp Running Hard
loading Python…
Input
gains=[3, 5], moves=3
Expected
5

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