Simple Java Solution
Code\n\nimport java.math.*;\nclass Solution {\n   int row=0,col=0,temprow=0,tempcol=0;\n   HashMap<Integer,HashSet<Integer>> h=new HashMap<Integer,HashSet<Integ
# Code\n```\nimport java.math.*;\nclass Solution {\n   int row=0,col=0,temprow=0,tempcol=0;\n   HashMap<Integer,HashSet<Integer>> h=new HashMap<Integer,HashSet<Integer>>();\n   HashSet<Integer> hset=new HashSet<Integer>();\n    public Solution(int m, int n) {\n        row=m;\n        col=n;\n        temprow=m;\n        tempcol=n;\n    }\n    \n    public int[] flip() {\n        int result[]=new int[2];\n     Random rand=new Random();\n     int r=rand.nextInt(row-hset.size());\n     int count=0;\n     for(int i=0;i<row;i++)\n     {\n        if(!hset.contains(i))\n        {\n            if(count==r)\n            {\n                r=i;\n                break;\n            }\n            count++;         \n        }\n     }\n     if(h.containsKey(r))\n     {\n          HashSet<Integer> hs=h.get(r);\n          count=0;\n          int c=rand.nextInt(col-hs.size());\n          for(int i=0;i<col;i++)\n          {\n                if(!hs.contains(i))\n                {\n                    if(c==count)\n                    {\n                          c=i;\n                          break;\n                    }\n                    count++;\n                }\n          }\n          hs.add(c);\n          h.put(r,hs);\n          if(hs.size()==col)\n          {\n            hset.add(r);\n          }  \n              result[1]=c;\n\n     }else\n     {\n        int c=rand.nextInt(col);\n        HashSet<Integer> hs=new HashSet<Integer>();\n         hs.add(c);\n          h.put(r,hs);\n          if(hs.size()==col)\n          {\n            hset.add(r);\n          }  \n              result[1]=c;\n     }\n     result[0]=r;\n     return result;\n    }\n    \n    public void reset() {\n        row=temprow;\n        col=tempcol;\n        h=new HashMap<Integer,HashSet<Integer>>();\n        hset=new HashSet<Integer>();\n    }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(m, n);\n * int[] param_1 = obj.flip();\n * obj.reset();\n */\n```
['Java']