Java | 6ms | easy understanding with comments and images
This is like this one https://leetcode.com/problems/maximal-rectangle/\nbut since each block can move, we cannot use that method (it will cause TLE).\nMy though
This is like this one [https://leetcode.com/problems/maximal-rectangle/](http://)\nbut since each block can move, we cannot use that method (it will cause TLE).\nMy thought is like this :  \n1. we need the rectangle for each column so we need to memorize that. --> change the matrix\n2. the columns can move   ----> sort it!\n3. calculate the max  --> from end (largest) to beginning (smallest) the larger would contain the smaller one. \n \nIf you like this solution, please leave your upvote :D\n```\n/*  build the matrix to:\n\t\t\t\t [ [1, 0, 1, 1]                                      [ [1, 0, 1, 1]  \n\t\t\t\t   [1, 0, 1, 0]                   -->                  [2, 0, 2, 0] \n\t\t\t\t   [0, 1, 1, 0] ]                                      [0, 1, 3, 0] ]\n*/\nclass Solution {\n    public int largestSubmatrix(int[][] matrix) {\n        for(int i = 1; i < matrix.length; i++){\n            for(int j = 0; j < matrix[0].length; j++){\n                if(matrix[i][j] == 1){\n                    matrix[i][j] = matrix[i - 1][j] + 1;\n                }\n            }\n        }\n        \n        int count = 0;\n        \n        for(int i = 0; i < matrix.length; i++){\n            Arrays.sort(matrix[i]);                                      // sort the Array : e.g. from [2,3,0, 1, 2,3] to [0,1,2,2,3,3]\n            for(int j = 1; j <= matrix[0].length; j++){\n                count = Math.max(count, j * matrix[i][matrix[0].length - j]);            // cauculate the max\n            }\n        }\n        \n        return count;\n    }\n}\n```\n![image](https://assets.leetcode.com/users/images/7dbb0d01-1541-4170-b026-a8d6d7e6a551_1610863787.1075761.png)\n\n\n
[]