1ms solution. Pattern based logic
Complexity\n- Time complexity:\nO(1)\n\n- Space complexity:\nO(1)\n\n# Code\njava []\n/**\n        n=5, k=6\n        0->0\n        1->1\n        2->2\n        3
# Complexity\n- Time complexity:\nO(1)\n\n- Space complexity:\nO(1)\n\n# Code\n```java []\n/**\n        n=5, k=6\n        0->0\n        1->1\n        2->2\n        3->3\n        4->4\n        \n        5->3\n        6->2\n        7->1\n        8->0\n\n        9->1\n        10->2\n        11->3\n        12->4\n\n        13->3\n        14->2\n        15->1\n        16->0\n\n        17->1\n        18->2\n        19->3\n        20->4\n\n    Pattern goes through completely on the first try with n iterations. \n    Forth that, it repeats iteself in batches of (n-1) \n         */\nclass Solution {\n    public int numberOfChild(int n, int k) {\n\n        if(k<n)\n            return k;\n        k-=(n);\n        if((k/(n-1))%2==0){\n            return(n-2-(k%(n-1)));\n        }else{\n            return(1+(k%(n-1)));\n        }\n    }\n}\n```
['Java']