Easy to understand - Java
Disclaimer: Like/Upvode if you like the solutions as it help me a lot guys :D\n\n# Intuition\n\nThe problem is about simulating a circular game where players ar
##### Disclaimer: Like/Upvode if you like the solutions as it help me a lot guys :D\n\n# Intuition\n\nThe problem is about simulating a circular game where players are eliminated in a cyclic manner with an increasing step size. By keeping track of eliminated players using a boolean array, we can determine which players remain at the end.\n\n## Approach\n\n1. **Initialize Players**:\n   - Use a boolean array `players` of size `n` to track whether a player is eliminated (`true`) or not (`false`).\n   - Initialize `currentK` to `k` and the current index `i` to `0`.\n\n2. **Simulate Elimination**:\n   - While loop to simulate the elimination process:\n     - If the current player `i` is already eliminated, break the loop.\n     - Mark the current player `i` as eliminated.\n     - Move to the next player by updating `i` to `(i + currentK) % n`.\n     - Increase `currentK` by `k` for the next elimination step.\n\n3. **Determine Losers**:\n   - Create an `ArrayList` to store the indices of players who were never eliminated.\n   - Iterate through the `players` array, adding the 1-based index of players who are still in the game to the `ArrayList`.\n\n4. **Convert to Array**:\n   - Convert the `ArrayList` to an `int[]` array to meet the return type requirement.\n\n5. **Return Result**:\n   - Return the array of players who were never eliminated.\n\n## Complexity\n\n- **Time Complexity**: O(n), where n is the number of players. The while loop and subsequent for loop each iterate at most `n` times.\n\n- **Space Complexity**: O(n), where n is the number of players. This space is used by the boolean array and the `ArrayList`.\n\n## Code\n\n```Java\nclass Solution {\n     public int[] circularGameLosers(int n, int k) {\n        boolean[] players = new boolean[n];\n        int currentK = k;\n        int i = 0;\n\n        while (true) {\n            if (players[i]) {\n                break;\n            }\n            players[i] = true;\n            i = (i + currentK) % n;\n            currentK += k;\n        }\n\n        ArrayList<Integer> losers = new ArrayList<>();\n        for (int j = 0; j < n; j++) {\n            if (!players[j]) {\n                losers.add(j + 1);\n            }\n        }\n\n        int[] result = new int[losers.size()];\n        for (int j = 0; j < losers.size(); j++) {\n            result[j] = losers.get(j);\n        }\n\n        return result;\n    }\n}\n```
['Java']