C++ Solution || Goldman Sachs Archive || O(n * m) time 90% Faster || Space Optimized || Set
Intuition\n Describe your first thoughts on how to solve this problem. \nYou cannot use a 2D vector or 2D array here due to space constraints. \n\n# Complexity\
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nYou cannot use a 2D vector or 2D array here due to space constraints. \n\n# Complexity\n- Time complexity: O(m * n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(m * n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n\n    set<pair<int, int>> used;\n    int m, n;\n\n    Solution(int _m, int _n) {\n        m = _m; n = _n;\n        srand(time(0));\n    }\n    \n    vector<int> flip() {\n        vector<int> chosen = {rand() % m, rand() % n};\n        while(used.find({chosen[0], chosen[1]}) != used.end()){\n            chosen[0] = rand() % m; chosen[1] = rand() % n;\n        }\n        used.insert({chosen[0], chosen[1]});\n        return chosen;\n    }\n    \n    void reset() {\n        used.clear();\n    }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(m, n);\n * vector<int> param_1 = obj->flip();\n * obj->reset();\n */\n```
['C++']