easy solution with dp.
Intuition\nfind all squares (n * n) and sum n by each the squares that are adjacent to the right and to the down with the same size of my current square, the an
# Intuition\nfind all squares (n * n) and sum n by each the squares that are adjacent to the right and to the down with the same size of my current square, the answer is the max of these sums.\n# Approach\n- find alls squares (n * n):\nfor this, we movent from left to right for alls row in my square, if my current cell is one, the max square (n * n) is the min between (left cell in this row, up cell in this colum, and left cell in the up row) + 1. \n\n- find alls rectangle (n * m) where m>=n:\nafter find the squares (n * n), we need to find alls squares that are contiguos and after sum ths, the second n in the operation (n * n) augmenter to m or the first n in the operation (n * n) augmenter.\nfor this, we have to travel for all cells in my tablet, if this cells have an one, we have to move to the maximal right cell, where alls cells in this range if the same square (n * n) and the sum is (n * n)+n * (range) move to the maximal down cell where alls cells in this range if the same square (n * n) and the sum is (n * n)+n * (range) for this cell the answer is the maximal betwen this two case, and the answer of this problem is the maximal the alls maximal found.\n# Complexity\n- Time complexity: O(N * M * max(N, M))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N*M)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maximalRectangle(vector<vector<char>>& matrix) {\n        \n        vector<vector<int>>table(matrix.size(), vector<int>(matrix[0].size()));\n\n        int i, j, k, l, maxi = 0, counter1, counter2;\n\n        for(i = 0; i<matrix.size(); i++){\n            table[i][0] = (matrix[i][0] == \'1\');\n        }\n        for(i = 0; i<matrix[0].size(); i++){\n            table[0][i] = (matrix[0][i] == \'1\');\n        }\n\n        for(i = 1; i<matrix.size(); i++){\n            for(j = 1; j<matrix[0].size(); j++){\n                if(matrix[i][j] == \'1\'){\n                    table[i][j] = min({table[i][j-1], table[i-1][j], table[i-1][j-1]})+1;\n                }\n            }\n        }\n\n        for(i = 0; i<matrix.size(); i++){\n            for(j = 0; j<matrix[0].size(); j++){\n                if(matrix[i][j] == \'1\'){\n                    counter1 = table[i][j] * table[i][j];\n                    counter2 = table[i][j] * table[i][j];\n                    for(k = i+1; k<matrix.size() && table[i][j] <= table[k][j] && table[k][j]; k++){\n                        counter1+=table[i][j];\n                    }\n                    for(l = j+1; l<matrix[0].size() && table[i][j] <= table[i][l] && table[i][l]; l++){\n                        counter2+=table[i][j];\n                    }\n                    maxi = max({counter1, counter2, maxi});\n                }\n            }\n        }\n\n        return maxi;\n    }\n};\n```
['Dynamic Programming', 'C++']