Sponsored
Sponsored
Solve with full IDE support and test cases
Use these hints if you're stuck. Try solving on your own first.
The ball will go back to child 0 after <code>2 * (n - 1)</code> seconds and everything is the same as time 0.
So the answer for <code>k</code> is the same as the answer for <code>k % (2 * (n - 1))</code>.