Python O(n) Tc and o(1) Sc
Intuition\nAfter every n-1 seconds the ball will change it\'s direction\nAfter every 2(n-1) seconds the ball will repeat it\'s previous cycle\n\n# Approach\n1 .
# Intuition\nAfter every n-1 seconds the ball will change it\'s direction\nAfter every 2*(n-1) seconds the ball will repeat it\'s previous cycle\n\n# Approach\n1 . So we can update k value as k = k%(2*(n-1)) (bcz same cycle will repeat)\n\n2 . We can keep track of direction of ball by using direction variable which will change for (n-1) position\n\n# Complexity\n- Time complexity : O(n) \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def numberOfChild(self, n: int, k: int) -> int:\n        total_steps = 2*(n-1)\n        k = k % total_steps\n        position = 0\n        direction = 1\n        for _ in range(k):\n            position += direction\n            if position == 0 or position == n - 1:\n                direction *= -1\n        \n        return position\n```
['Math', 'Python3']