Simple O(1) solution
Intuition\n Describe your first thoughts on how to solve this problem. \nThe loop size is 2 * n - 2.\n\n### Approach\n Describe your approach to solving the pro
### Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe loop size is `2 * n - 2`.\n\n### Approach\n<!-- Describe your approach to solving the problem. -->\nWe can query the remainder of the loop, forward or backward.\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 {\n  public int numberOfChild(int n, int k) {\n    // loop size 2 * n - 2\n    k = k % (2 * n - 2);\n    if (k < n) {\n      // forward\n      return k;\n    }\n\n    // backward\n    return n - 1 - (k - (n - 1));\n  }\n}\n\n```
['Math', 'Java']