O(1) Time & Space Complexity | Easy Peasy
Approach\nAs we have to return the [i,j] where, matrix[i][j] = 0 but there\'s no need to actually forming of matrix as we also have to reset it which will can l
# Approach\nAs we have to return the ```[i,j] where, matrix[i][j] = 0``` but there\'s no need to actually forming of matrix as we also have to reset it which will can lead to time or memory limit warnings. And also we need to maintain the ```equally likely condition```, So we can approach this question in a very simple manner (now go to code)\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(1)\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    int n,m;\n    int i = 0,j = 0; // start with first row and first column\n    Solution(int m, int n) {\n        this->n = n;\n        this->m = m;\n    }\n    \n    vector<int> flip() {\n        int I = i, J = j; // for returning purpose\n        if(j + 1 < n) j++; // will iterate over columns till we can\n        else if(i + 1 < m){ // will switch to next row and first col\n            i++;\n            j = 0;\n        }\n        else i = 0,j = 0; // will point back to first row and col\n        // work as reset and continue to cycle again\n        return {I,J};\n    }\n    \n    void reset() {\n        // no need of it, we have taken care of it in the flip() part\n    }\n};\n\n```
['C++']