C++ 12 ms beats 100%
it is no difference from 1-D problem\nuse unordered_map to record numbers that already popped out and reduce the rand() call range each time\n\nclass Solution {
it is no difference from 1-D problem\nuse unordered_map to record numbers that already popped out and reduce the rand() call range each time\n```\nclass Solution {\npublic:\n    Solution(int n_rows, int n_cols) {\n        N = n_rows * n_cols;\n        n = N;\n        m = n_cols;\n    }\n    \n    vector<int> flip() {\n        int i = rand() % n;\n        \n        int ret;\n        if (mapp.count(i)) {\n            ret = mapp[i];\n        } else {\n            ret = i;\n        }\n        \n        if (mapp.count(n - 1)) {\n            mapp[i] = mapp[n - 1];\n        } else {\n            mapp[i] = n - 1;\n        }\n        \n        --n;\n        \n        return {ret / m, ret % m};\n    }\n    \n    void reset() {\n        mapp.clear();\n        n = N;\n    }\n    \nprivate:\n    int N, n, m;\n    unordered_map<int, int> mapp;\n};\n```
[]