find-the-losers-of-the-circular-game
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\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[] circularGameLosers(int n, int k) \n    {\n\n        int sum=k+1;\n        int i=2,j=0;\n        int  index=sum%n;\n         if(index==0)\n            {\n                index=n;\n            }\n        \n        Set<Integer> set = new HashSet<>();\n        set.add(1);\n         int[] ans1 ={};\n        if(n==1)\n        {\n            return ans1;\n        }\n        while(!set.contains(index))\n        {\n           \n           \n            // System.out.println(index);\n            if(!set.contains(index))\n            {\n            set.add(index);\n            }\n            sum=sum+i*k;\n            i++;\n            index=sum%n;\n             if(index==0)\n            {\n                index=n;\n            }\n        }\n        //System.out.println(set);\n      \n        int[] ans =new int[n-set.size()];\n        for(i=1;i<=n;i++)\n        {\n            if(!set.contains(i))\n            {\n                ans[j]=i;\n                // System.out.println(ans[j]);\n                j++;\n            }\n        }\n        return ans;\n        \n    }\n}\n```
['Java']