3178. Find the Child Who Has the Ball After K Seconds
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int numberOfChild(int n, int k) {
        int position = 0;  // Start with child 0
        int direction = 1; // Ball is passing to the right initially
        
        for (int i = 0; i < k; ++i) {
            position += direction;  // Move ball in the current direction
            // Check if the ball has reached the boundary and reverse direction
            if (position == 0 || position == n - 1) {
                direction = -direction;  // Reverse direction
            }
        }
        
        return position;
    }
};

```
['C++']