5Lines simple code O(K)
\n\n# Code\n\nclass Solution:\n    def numberOfChild(self, n: int, k: int) -> int:\n        posneg,j=1,0\n        for i in range(k):\n            j+=posneg\n   
\n\n# Code\n```\nclass Solution:\n    def numberOfChild(self, n: int, k: int) -> int:\n        posneg,j=1,0\n        for i in range(k):\n            j+=posneg\n            if j==0 or j==n-1:\n                posneg*=-1\n        return j\n```
['Python3']