Tap here to switch tabs
Problem
Submissions

Problem: Find the Child Who Has the Ball After K Seconds

med
30 min
Try to solve the Find the Child Who Has the Ball After K Seconds problem.

Statement

There are n children standing in a line, numbered from 00 to n −1- 1 from left to right.

Initially, at time 00, child 00 holds a ball. Every second, the child currently holding the ball passes it to the adjacent child in the current direction of movement. The ball starts moving from left to right. Whenever the ball reaches either end of the line (child 00 or child n −1- 1), the direction of passing reverses.

Return the index of the child who is holding the ball after k seconds.

Constraints:

  • 2≤2 \leq n ≤50\leq 50

  • 1≤1 \leq k ≤50\leq 50

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Child Who Has the Ball After K Seconds

med
30 min
Try to solve the Find the Child Who Has the Ball After K Seconds problem.

Statement

There are n children standing in a line, numbered from 00 to n −1- 1 from left to right.

Initially, at time 00, child 00 holds a ball. Every second, the child currently holding the ball passes it to the adjacent child in the current direction of movement. The ball starts moving from left to right. Whenever the ball reaches either end of the line (child 00 or child n −1- 1), the direction of passing reverses.

Return the index of the child who is holding the ball after k seconds.

Constraints:

  • 2≤2 \leq n ≤50\leq 50

  • 1≤1 \leq k ≤50\leq 50