Eliminate players that got the ball until you try to erase someone that's not there
Intuition\nCreate all possible losers, and start eliminating possibilities.\n\n# Approach\nHelper function- helps find the player that got the ball and erases h
# Intuition\nCreate all possible losers, and start eliminating possibilities.\n\n# Approach\nHelper function- helps find the player that got the ball and erases him. If he\'s not in the result vector, it means he already had the ball, so we\'re done playing (returns false).\n\n# Complexity\n- Time complexity:\n$$O(n^2)$$ --> We\'re playing $$n$$ moves at the most.\n`std::find` has $$O(n)$$ running time, and we\'re running it $$O(n)$$ times. \n\n- Space complexity:\n$$O(n)$$ --> Added the `res` vector for the result.\n\n# Code\n```\nclass Solution {\npublic:\n    bool findAndErase(vector<int>& vec, int val) {\n        auto it = std::find(vec.begin(), vec.end(), val);\n        if (it == vec.end())\n            return false;\n        vec.erase(it);\n        return true;\n    }\n\n    vector<int> circularGameLosers(int n, int k) {\n        vector<int> res;\n        res.reserve(n - 1); // Player 1 can never lose\n        for (auto i = 2; i <= n; i++) {\n            res.push_back(i);\n        }\n\n        int ballPos(1);\n        for (auto i = 1; i <= n; i++) {\n            ballPos += k * i;\n            // mod isn\'t enough here\n            while (ballPos > n)\n                ballPos -= n;\n            if (!findAndErase(res, ballPos))\n                break;  // Player got the ball twice\n        }\n\n        return res;\n    }\n};\n```
['C++']