Java Priority Queue Solution
https://achievementguru.com/leetcode-1727-largest-submatrix-with-rearrangements-java-solution/\n\nclass Solution {\n    public int largestSubmatrix(int[][] matr
https://achievementguru.com/leetcode-1727-largest-submatrix-with-rearrangements-java-solution/\n```\nclass Solution {\n    public int largestSubmatrix(int[][] matrix) {\n         //Store matrix[i][j]= total number of consecutive 1s along column j ending at index (i,j).\n        for(int i=1;i<matrix.length;i++)  //Start from row 1 because row 0 will be unaffected as no row above it.\n        {\n            for(int j=0;j<matrix[i].length;j++)\n            {\n                if(matrix[i][j]==0) continue;\n                else  matrix[i][j]=matrix[i-1][j]+1;\n            }\n        }\n        \n        int maxSize=0;\n        for(int i=0;i<matrix.length;i++)\n        {\n           \n            PriorityQueue<Integer> pq  =  new PriorityQueue<Integer>();// minheap\n            for(int j=0;j<matrix[i].length;j++)\n            {\n                if(matrix[i][j]>0)  pq.add(matrix[i][j]); // Add all the entries from row i in minheap\n            }\n            int size=0,curr=0;\n            /*\n                In current row, total entries with value k or greater than k will contribute the squares of\n\t\t\t\tsize=k*(number of squares of size k or greater than k).Largest square ending at current\n\t\t\t\trow= k * (all entries greater than or equal to k in current row) for all ks in current row\n            */\n            while(!pq.isEmpty())  \n            {\n                curr=pq.peek(); \n                \n                size=curr*pq.size();\n                maxSize=Math.max(maxSize,size);\n                \n                pq.poll();\n            }\n        }\n        return maxSize;\n        \n        \n        \n    }\n}\n```
['Heap (Priority Queue)', 'Java']