✔💯 DAY 409 | EASY | 100% | | [PYTHON/JAVA/C++] | EXPLAINED 🆙🆙🆙
Please Upvote as it really motivates me \uD83C\uDD99\uD83C\uDD99\uD83C\uDD99\n# Intuition & Approach\n Describe your approach to solving the problem. \ncreate a
# Please Upvote as it really motivates me \uD83C\uDD99\uD83C\uDD99\uD83C\uDD99\n# Intuition & Approach\n<!-- Describe your approach to solving the problem. -->\ncreate an array vis of the same size as n and fill it with zeros. Then they iterate over the array and update the value of p using the given formula. They also check if p has already been visited before and break the loop if it has. Finally, they create a list of all the elements that have not been visited and return it.\n\n# Complexity\n- Time complexity:o(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:o(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\npublic int[] circularGameLosers(int n, int k) {\n    int  vis[] = new int[n+1];\n    vis[1]=1;\n    int p = 1;\n    for(int i=1;i<=n;i++){\n        p=(p+(k*i) )%(n);\n        if(p==0) p=n;\n        if(vis[p]==1) break;\n        vis[p]=1;\n        \n    }\n    var list = new ArrayList<Integer>();\n    for(int i=1;i<=n;i++){\n        if(vis[i]==0){\n            list.add(i);\n        }\n    }return list.stream().mapToInt(i->i).toArray();\n}\n```\n\n```python []\ndef circularGameLosers(self, n: int, k: int) -> List[int]:\n        vis = [0] * (n + 1)\n        vis[1] = 1\n        p = 1\n        for i in range(1, n + 1):\n            p = (p + k * i) % n\n            if p == 0:\n                p = n\n            if vis[p] == 1:\n                break\n            vis[p] = 1\n        return [i for i in range(1, n + 1) if vis[i] == 0]\n```\n```c++ []\nvector<int> circularGameLosers(int n, int k) {\n        vector<int> vis(n + 1, 0);\n        vis[1] = 1;\n        int p = 1;\n        for (int i = 1; i <= n; i++) {\n            p = (p + k * i) % n;\n            if (p == 0) {\n                p = n;\n            }\n            if (vis[p] == 1) {\n                break;\n            }\n            vis[p] = 1;\n        }\n        vector<int> res;\n        for (int i = 1; i <= n; i++) {\n            if (vis[i] == 0) {\n                res.push_back(i);\n            }\n        }\n        return res;\n    }\n
['Python', 'C++', 'Java', 'Python3']