Ctrl K

The Shuttle Robot

Easy
You get an array of non-negative integers cells: a row of cells, each holding a counter. A robot is placed on a cell whose counter is 0 and picks a direction, left or right. Then it repeats: - if it has left the row, the process stops; - if the counter under it is 0, it steps once in its current direction; - otherwise it decreases that counter by 1, turns around and steps once in the new direction. A start (cell plus direction) is good if every counter is zero once the process stops. Return the number of good starts.
Example 1
cells=[3, 0, 1, 0, 1] → 1

At cell 1 the sums are 3 on the left and 2 on the right: everything is cleared only when heading left, toward the larger sum. At cell 3 the sums 4 and 1 are too far apart, so both directions fail.

Example 2
cells=[0] → 2

Everything is already zero, so both directions work.

Example 3
cells=[5, 0, 1] → 0

The side sums are 5 and 1, too far apart: the robot always leaves non-zero cells behind.

Constraints
  • 1 ≤ len(cells) ≤ 100
  • 0 ≤ cells[i] ≤ 100
  • At least one element of cells is 0
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBack at the Dock EasyShuttle Seat Plan MediumWho Refills the Coffee Beans MediumRunning Sum Waves MediumPump Rods at Their Peak Hard
loading Python…
Input
cells=[3, 0, 1, 0, 1]
Expected
1

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