Find the Child Who Has the Ball After K Seconds - Simplified Solution
Problem OverviewWe have n children standing in a line, and a ball is passed between them every second. The ball starts with child 0 and moves to the right. When
# Problem Overview  
We have `n` children standing in a line, and a ball is passed between them every second. The ball starts with child `0` and moves to the right. When the ball reaches either end of the line, the passing direction reverses. The task is to determine which child has the ball after `k` seconds.  

# Intuition  
The ball movement follows a repeating pattern:
- It takes `n-1` seconds for the ball to travel from one end of the line to the other.
- The direction of the ball's movement is determined by the number of complete cycles (`k / (n-1)`):  
  - If the cycle count is even, the ball moves forward.  
  - If the cycle count is odd, the ball moves backward.  
- The position within the current cycle can be identified using the remainder (`k % (n-1)`).

# Approach  
1. Calculate the number of complete cycles and the remainder using `k / (n-1)` and `k % (n-1)`.  
2. If the cycle count is even, the ball's position is `rem`.  
3. If the cycle count is odd, the ball's position is `n - rem - 1`.  

# Complexity  
- **Time complexity:** $$O(1)$$ — Only basic arithmetic operations are performed.  
- **Space complexity:** $$O(1)$$ — No additional memory is used.  

# Code  
```java
class Solution {
    public int numberOfChild(int n, int k) {
        int rem = k % (n - 1);
        int cycle = k / (n - 1);
        if (cycle % 2 == 0) {
            return rem;
        } else {
            return n - rem - 1;
        }
    }
}

['Math', 'Simulation', 'Java']