2-line O(1) sol||0ms beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nModular arithmetic with period N=2*(n-1)\n# Approach\n Describe your approach to solvin
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nModular arithmetic with period `N=2*(n-1)`\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Modular arithmetic `x=k%N;`\n2. The answer is `(x<n)?x:N-x`\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n# Code||0ms beats 100%\n```\nclass Solution {\npublic:\n    int numberOfChild(int n, int k) {\n        int N=2*n-2, x=k%N;\n        return (x<n)?x:N-x;\n    }\n};\n\n```
['Math', 'C++']