3178. Find the Child Who Has the Ball After K Seconds

You are given two

positiveintegers`n`

and`k`

. There are`n`

children numbered from`0`

to`n - 1`

standing in a queuein orderfrom left to right.Initially, child 0 holds a ball and the direction of passing the ball is towards the right direction. After each second, the child holding the ball passes it to the child next to them. Once the ball reaches

eitherend of the line, i.e. child 0 or child`n - 1`

, the direction of passing isreversed.Return the number of the child who receives the ball after

`k`

seconds.

1 | class Solution { |