Skip to content

Practice Find the Child Who Has the Ball After K Seconds

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3178
LeetCode Problem

Find the Child Who Has the Ball After K Seconds

Problem Statement

You are given two positive integers n and k. There are n children numbered from 0 to n - 1 standing in a queue in order from 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 either end of the line, i.e. child 0 or child n - 1, the direction of passing is reversed. Return the number of the child who receives the ball after k seconds. Example 1: Example 2: Example 3: Constraints: Note: This question is the same as 2582: Pass the Pillow.

Source: Find the Child Who Has the Ball After K Seconds on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 3, k = 5
Output
1

# Example 2

Input
n = 5, k = 6
Output
2

# Example 3

Input
n = 4, k = 2
Output
2

Constraints

2 <= n <= 50
1 <= k <= 50

Related LeetCode Problems

Practice more problems similar to Find the Child Who Has the Ball After K Seconds.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.