Simple Math || O(1) 100% Faster Solution
Intuition\nFor a complete cycle there will be total of 2(n - 1) children and time will be k % 2(n - 1) because rest of the time complete cycles occur.\nNow if(t
# Intuition\nFor a complete cycle there will be total of 2*(n - 1) children and time will be k % 2*(n - 1) because rest of the time complete cycles occur.\nNow if(time < n) means finally the ball was in left to right direction and answer would be k%l. Else it will be in right to left direction and answer would be 2*(n - 1) - k%l\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n<!-- # Approach -->\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(1)$$\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 {\npublic:\n    int numberOfChild(int n, int k) {\n        int l = 2 * (n - 1);\n        int sec = k % l;\n        \n        if (sec < n) {\n            return sec;\n        } else {\n            return l - sec;\n        }\n    }\n};\n\n```
['C++']