Easy Brute Force Approach | Easy to Understand | Beats 100% of users
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nStep 1: \ntake an array
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStep 1: \ntake an array arr[] of size n to hold the child.\nwill take a pointer p initially at arr[0] and variable count to couter the variable k and control the number of operation\n\nStep 2: \nwill make two while loop one will be for left to right direction, and as q reach to last element of arr[] then we come out of first while loop and then mark q = n-1 and now another while loop to change the direction if count is still less than k and then mark q = 0; and this process will be repeated till count != k.\n\nStep 3: \nOnce the count == k, we come out of while loop and return the value of p\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int numberOfChild(int n, int k) {\n        int arr[] = new int[n];\n        for(int i=0; i<n; i++){\n            arr[i] = i;\n        }\n        int count = 0;\n        int p = arr[0], q = 0;\n        while(count != k){\n            while(count != k && q < n-1){\n                count++;\n                q++;\n                p = arr[q];\n            } \n            q = n-1;\n            while(count != k && q > 0){\n                count++;\n                q--;\n                p = arr[q];\n            }\n            q = 0;\n        }\n        return p;\n    }\n}\n```
['Java']