O(1) approach explained detailly
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem can be visualized as children sitting in a circle where the distribution of
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem can be visualized as children sitting in a circle where the distribution of items happens in a specific pattern, reversing direction after completing a round. By carefully calculating the direction and the remainder, we can determine which child receives the k-th item\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.Direction Calculation:\n\n*Every (n-1) items, the direction changes. The direction can be    determined by dividing k by n-1.\n\n*If the result is even, it means the direction is still forward. If odd, the direction has reversed.\n\nRemainder Calculation:\n\n*The remainder when k is divided by n-1 tells us the position in the current segment.\n\n*If the direction is still forward (even number of complete rounds), the child can be directly determined by the remainder.\n\n*If the direction has reversed (odd number of complete rounds), the position must be calculated backwards from the end.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(1) - The solution involves basic arithmetic operations that take constant time.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1) - No extra space is used beyond the input variables.\n\n# Code\n```\nclass Solution {\npublic:\n    int numberOfChild(int n, int k) {\n        \n        int direction = k / (n - 1);\n        int remainder = k % (n - 1);\n\n        if(direction & 1){\n            return n - remainder - 1;\n        }\n        return remainder;\n    }\n};\n```
['C++']