519. Random Flip Matrix
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
private:
    int m, n, total;
    unordered_map<int, int> map;
    
public:
    Solution(int m, int n) {
        this->m = m;
        this->n = n;
        this->total = m * n;
    }
    
    vector<int> flip() {
        int index = rand() % total;
        total--;
        int target = map.count(index) ? map[index] : index;
        map[index] = map.count(total) ? map[total] : total;
        return {target / n, target % n};
    }
    
    void reset() {
        map.clear();
        total = m * n;
    }
};

```
['C++']