O(1) Java solution using simple Math logic
Intuition\nThe ball starts with child 0 and moves to the right. When it reaches the end (either child 0 or child n\u22121), the direction reverses. The problem 
# Intuition\nThe ball starts with child 0 and moves to the right. When it reaches the end (either child 0 or child n\u22121), the direction reverses. The problem is to determine which child has the ball after k seconds. The key insight is to notice the periodic nature of the ball\'s movement.\n\n# Complexity\n- Time Complexity: $$O(1)$$ since all operations (modulus and division) are constant time.\n- Space Complexity: $$O(1)$$ since no additional space proportional to the input size is used.\n\n# Code\n```\nclass Solution {\n    public int numberOfChild(int n, int k) {\n        if(k < n) return k;\n        int mod = k%(n-1);\n        int times = (k-mod)/(n-1);\n        if(times%2 == 0) return  mod;\n        return n-1-mod;\n    }\n}\n```
['Java']