kids children standing in a line, numbered from 0 to kids - 1 from left to right. At the start child 0 holds the ball.
Every second the child with the ball hands it to a neighbor. The ball first travels to the right; whenever it reaches a child at either end (0 or kids - 1), it reverses direction.
Return the number of the child holding the ball after seconds seconds.kids=4, seconds=5 → 1
The ball goes 0 → 1 → 2 → 3, reaches the end after 3 seconds and turns back: 3 → 2 → 1. After 5 seconds child 1 has it.
kids=2, seconds=3 → 1
Two children just toss it back and forth: 0 → 1 → 0 → 1.
kids=6, seconds=2 → 2
kids=4, seconds=5
1
Run checks the first 3 tests in your browser. Submit checks all 85 tests on the server, hidden ones included.