begineer friendly || 100% beat
IntuitionApproachComplexity

Time complexity:
O(n)


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(n)

- Space complexity:
O(1)

# Code
```java []
class Solution {
    public int numberOfChild(int n, int k) {
        int dir=1; // 1->right -1->left
        int children=0;
        while(k-- > 0){
            children+=dir;
            if(children==n-1 || children==0) dir=-dir;
        }
        return children;
    }
}
```
['Java']