Java HashSet
Intuition\n Describe your first thoughts on how to solve this problem. \nEach time it goes to the Remaider\'s friend. Use hashMap to cache all the friend (remai
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nEach time it goes to the Remaider\'s friend. Use hashMap to cache all the friend (remainder) caught the ball.\n\nNote it is 1 indexed, so has to transform to 0 indexed for easy to adop remaineder.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n# Code\n```\npublic int[] circularGameLosers(int n, int k) {\n    Set<Integer> vis = new HashSet<>();\n    int i = 0, rem = 0;\n    while(true) {\n        rem = (rem + k * i++) % n;\n        if (!vis.add(rem)) break; //rem has been visited\n    }\n    int j = 0, res[] = new int[n - vis.size()];\n    for (i = 0; i < n; i++) {\n        if (!vis.contains(i)) res[j++] = i + 1;\n    }\n    return res;\n}\n```
['Java']