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.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.
cells=[0] → 2
Everything is already zero, so both directions work.
cells=[5, 0, 1] → 0
The side sums are 5 and 1, too far apart: the robot always leaves non-zero cells behind.
cells=[3, 0, 1, 0, 1]
1
Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.