O(1) || Math
Intuition\n- Simplify the problem by understanding the cyclic nature of the ball passing. By calculating the number of complete back-and-forth trips and the rem
# Intuition\n- Simplify the problem by understanding the cyclic nature of the ball passing. By calculating the number of complete back-and-forth trips and the remaining steps, we can determine the final position of the ball. \n- If the total number of complete trips is even, the ball continues in the forward direction.\n- If odd, it reverses direction.\n\n# Complexity\n- Time complexity: $$O(1)$$\n\n- Space complexity: $$O(1)$$\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    int numberOfChild(int n, int k) {\n        n--; // Decrement n to simplify calculation (so range is now 0 to n-1)\n        int rounds = k / n; // Calculate the number of complete back-and-forth trips\n        int rem = k % n; // Calculate the remaining steps after the last complete trip\n\n        if(rounds % 2 == 0) {\n            // If the number of complete back-and-forth trips is even\n            return rem; // The ball is passed forward from the start\n        } else {\n            // If the number of complete back-and-forth trips is odd\n            return (n - rem); // The ball is passed backward from the end\n        }\n    }\n};\n```\n```Java []\nclass Solution {\n    public int numberOfChild(int n, int k) {\n        n--; // Decrement n to simplify calculation (so range is now 0 to n-1)\n        int rounds = k / n; // Calculate the number of complete back-and-forth trips\n        int rem = k % n; // Calculate the remaining steps after the last complete trip\n\n        if (rounds % 2 == 0) {\n            // If the number of complete back-and-forth trips is even\n            return rem; // The ball is passed forward from the start\n        } else {\n            // If the number of complete back-and-forth trips is odd\n            return n - rem; // The ball is passed backward from the end\n        }\n    }\n}\n\n```\n```Python3 []\nclass Solution:\n    def numberOfChild(self, n: int, k: int) -> int:\n        n -= 1  # Decrement n to simplify calculation (so range is now 0 to n-1)\n        rounds = k // n  # Calculate the number of complete back-and-forth trips\n        rem = k % n  # Calculate the remaining steps after the last complete trip\n\n        if rounds % 2 == 0:\n            # If the number of complete back-and-forth trips is even\n            return rem  # The ball is passed forward from the start\n        else:\n            # If the number of complete back-and-forth trips is odd\n            return n - rem  # The ball is passed backward from the end\n\n```\n\n
['Math', 'C++', 'Java', 'Python3']