Simple solution using Math || O(1)
Intuition\nAfter 2 * (n-1) seconds, ball ends up with the first child. After n-1 seconds, the ball is with the last child.\n\n# Approach\nSo take reminder of k 
# Intuition\nAfter $$2 * (n-1)$$ seconds, ball ends up with the first child. After $$n-1$$ seconds, the ball is with the last child.\n\n# Approach\nSo take reminder of k with $$2 * (n-1)$$. If k is less than $$n-1$$ return k, else return $$(n-1) - (k - (n-1))$$ as the ball reaches the end $$n-1$$ seconds and runs backward.\n\n# Complexity\n- Time complexity: $$O(1)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimpl Solution {\n    pub fn number_of_child(n: i32, k: i32) -> i32 {\n        let k = k % (2 * (n - 1));\n        if k > (n-1) {\n            (n << 1) - 2 - k\n        } else {\n            k\n        }\n    }\n}\n```
['Rust']