Find the child who has the ball after k seconds📍 || Simple logic🎯|| Easy solution
IntuitionThe problem simulates the movement of a child along a straight path of n positions. The child starts at position 0 and moves one step at a time. When r
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem simulates the movement of a child along a straight path of n positions. The child starts at position 0 and moves one step at a time. When reaching either end (0 or n-1), the direction reverses. The goal is to determine the child's position after k steps.
# Approach
<!-- Describe your approach to solving the problem. -->
1. Initialization: Start at position 0 with a direction of +1 (moving forward).
2. Iteration: Move the child one step in the current direction (+1 for forward, -1 for backward).
3. Boundary Handling:
    - If the child reaches position 0, set the direction to +1.
    - If the child reaches position n-1, set the direction to -1.
4. Repeat for k steps and return the final position.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(k)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(1)
# Code
```java []
class Solution {
    public int numberOfChild(int n, int k) {
        int pos = 0;
        int direction = 1;
        int count = 0;
        while(count < k){
            // pos = i;
            if(pos == 0){
                direction = 1;
            }
            if(pos == n-1){
                direction = -1;
            }
            pos = pos+direction;
            count++;
        }
        return pos;
    }
}
```
['Math', 'Simulation', 'Java']