Two Methods Math & pointer
FIRST METHOD - Using Maths\n# Code\n\nclass Solution {\npublic:\n    int numberOfChild(int n, int k) {\n        int d=k/(n-1);\n        int r=k%(n-1);\n        
# FIRST METHOD - Using Maths\n# Code\n```\nclass Solution {\npublic:\n    int numberOfChild(int n, int k) {\n        int d=k/(n-1);\n        int r=k%(n-1);\n        if(d&1){\n            return n-r-1; // odd then cournt from end side\n        }\n        else return r; // even then count from front\n    }\n};\n```\n# SECOND METHOD - Using POINTER\n# Code\n```\nclass Solution {\npublic:\n    int numberOfChild(int n, int k) {\n        int i=0; // i indicate current position\n        int p=0; // direction\n        while(k--){\n            if(i==0)p=1;\n            if(i==n-1)p=-1;\n            i+=p;\n        }\n        return i;\n    }\n};
['Math', 'C++']