deque 🔥| C++
Code
# Code
```cpp []
class Solution {
public:
    int numberOfChild(int n, int k) {
        deque<int> dq(1, 0);

        bool flag1 = false;
        for (int i = 1; i <= k; ++i) {
            if (!flag1) {
                dq.push_back(i);

                if (dq.size() == n) {
                    flag1 = true;
                }
            } else if (flag1) {
                dq.pop_back();

                if (dq.size() == 1) {
                    flag1 = false;
                }
            }
        }

        return dq.size() - 1;
    }
};
```
['Queue', 'C++']