easy solution | beats 100%
Intuition\nThe ball is passed back and forth between the children, reversing direction when it hits either end (child 0 or child n-1). This back-and-forth movem
## Intuition\nThe ball is passed back and forth between the children, reversing direction when it hits either end (child 0 or child n-1). This back-and-forth movement can be tracked using a simple iterative approach.\n\n## Approach\n1. Start with the ball at position 0 and the direction set to 1 (moving to the right).\n2. Iterate `k` times, updating the position by the current direction.\n3. Whenever the ball reaches either end of the line (position 0 or n-1), reverse the direction.\n4. After `k` seconds, return the current position of the ball.\n\n## Complexity\n- Time complexity: $$O(k)$$, since we iterate `k` times.\n- Space complexity: $$O(1)$$, since we use only a constant amount of extra space.\n\n# Code\n```\nclass Solution {\npublic:\n    int numberOfChild(int n, int k) {\n        int position = 0; \n        int direction = 1; \n\n        for (int i = 0; i < k; ++i) {\n            position += direction;\n            \n            if (position == 0 || position == n - 1) {\n                direction *= -1;\n            }\n        }\n        \n        return position;\n    }\n};\n```
['C++']