Simplest Approach: Beats 100%
IntuitionApproachComplexity
Time complexity: O(k)

Space complexity: O(1)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(k)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int numberOfChild(int n, int k) {
        int position = 0; // Current position (child index)
        int direction = 1; // Direction: 1 means forward, -1 means backward

        for (int step = 1; step <= k; step++) {
            position += direction; // Move in the current direction

            // Change direction if we reach the first or last child
            if (position == 0) {
                direction = 1; // Move forward
            } else if (position == n - 1) {
                direction = -1; // Move backward
            }
        }

        return position; // Final position after k steps
    }
};

```
['C++']