🔥Simulation - Beginner Friendly | Clean Code | C++ |
Code\n\nclass Solution {\npublic:\n    int numberOfChild(int n, int k) {\n        if (k == 1)\n            return 1;\n        \n        int curr = 1;\n        b
# Code\n```\nclass Solution {\npublic:\n    int numberOfChild(int n, int k) {\n        if (k == 1)\n            return 1;\n        \n        int curr = 1;\n        bool dir = false;\n        k--;\n        while (k--)\n        {\n            if (curr == n - 1)\n                dir = true;\n            if (curr == 0)\n                dir = false;\n            \n            if (dir == false)\n                curr++;\n            if (dir == true)\n                curr--;\n            \n        }\n        \n        return curr;\n    }\n};\n```
['C++']