✅☑️ C++ solution fully commented with notes [random flip matrix]
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n# Approach\n Describe your approach to solving the problem. \nusing sliding and swa
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n![random flip matrix.jpg](https://assets.leetcode.com/users/images/8f7e6ca9-b5f4-4257-a3ad-846b1149e761_1706777932.3565657.jpeg)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nusing sliding and swapping \n\n# Complexity\n- Time complexity: 0(n) because n times rand function is called . the swap takes 0(1) time\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n// let m = 3, n = 4\n// so the 2d array would be \n//     0   1   2    3\n//     4   5   6    7\n//     8   9   10  11\n//     m*n = 3*4  = 12 , convert it to 1 d array, run loop from 0 to 11\n//     such that row = i / n\n//     col = i % n;\nmap<int,int> map;\nint m;\nint n;\nint total_zeroes ;\n    Solution(int m, int n) {\n        total_zeroes = m*n;\n        this->m = m;\n        this->n = n;\n    }\n    \n\n\n    vector<int> flip() {\n        //during swapping the index number and the number at the index would get changed\n        int r = rand() % total_zeroes; // random number from 0 to m*n -1 range\n        // the 2d array -> 1 d array indexing starts with zero remember\n        int actual = (map.count(r)) ? map[r] : r; // collect the removed element without losing\n        // as a elem is removed reduce the zeroes\n        total_zeroes--;\n        map[r] = map.count(total_zeroes)? map[total_zeroes] : total_zeroes;\n        //because we have converted the 2d array to 1d array\n        return { actual/n , actual % n };\n    }\n    \n    void reset() {\n        map.clear();\n        total_zeroes = m*n;\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```\n\nPlease upvote . comment your doubt i will make sure you understand
['Hash Table', 'C++']