Histogram-like Approach
Intuition\nThe challenge was to find the largest 1\'s submatrix after rearranging columns. My initial thought was to transform the problem into a histogram-like
# Intuition\nThe challenge was to find the largest `1`\'s submatrix after rearranging **columns**. My initial thought was to transform the problem into a **histogram**-like approach, treating rows as bases and columns as heights.\n\n# Approach\n1.    **Height Calculation**: First, transform the matrix such that each cell represents the height of `1`\'s up to that row.\n2.    **Sorting Rows**: Next, **sort** each row in **descending** order.\n3.    **Maximum Area Calculation**: Finally, calculate the maximum area for each row, considering the sorted heights and their positions.\n\n# Complexity\n- Time complexity: $$O(m\xD7nlogn)$$, where $$m$$ is the number of rows and $$n$$ is the number of columns. Sorting each row contributes to the $$nlog\u2061n$$ part.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$ as no extra space is needed apart from the input matrix transformation.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  static bool cmp(int x, int y) { return x > y; }\n\npublic:\n  int largestSubmatrix(vector<vector<int>> &matrix) {\n    int r = matrix.size();\n    int c = matrix[0].size();\n    for (int i = 0; i < c; i++) {\n      for (int j = 1; j < r; j++) {\n        if (matrix[j][i]) {\n          matrix[j][i] = matrix[j - 1][i] + 1;\n        }\n      }\n    }\n    int ans = 0;\n    for (int i = 0; i < r; i++) {\n      sort(matrix[i].begin(), matrix[i].end(), cmp);\n      for (int j = 0; j < c; j++) {\n        ans = max(ans, matrix[i][j] * (j + 1));\n      }\n    }\n    return ans;\n  }\n};\n```
['Array', 'Greedy', 'Sorting', 'Matrix', 'C++']