[C++] ✅ Histogram Max Area Finding Problem || Count ones and sort
Approach:\n\nImagine each column in the matrix as a vertical bar, where its height represents the count of consecutive ones above it, including itself.\n\nIt is
**Approach:**\n\nImagine each column in the matrix as a vertical bar, where its height represents the count of consecutive ones above it, including itself.\n\nIt is similar to **Histogram Area Finding Problem:** `Calculating the maximum area of a histogram for each row: This helps in determining the maximum rectangle that can be formed considering the consecutive 1s in each column.`\n\nFor example, the given matrix:\n```\n[[0,0,1],\n [1,1,1],\n [1,0,1]]\n```\nTransforming it into a \'height\' array gives us `[2, 0, 3]`. Sorting this array becomes `[3, 2, 0]`. \n\n**We can also sort it in ascending and use** `ans = max(ans,height[i] * (n-i));` **or for descending sort of heights we will assign** `ans = max(ans,height[i] * (i+1));` \n\nNow, after sorting \'height\' array, let\'s find the largest submatrix:\n- At column 0 with a height of 3, there\'s only one column,  so the area is 3x1=3.\n- Moving to column 1 with a height of 2, we have two columns that can form a base of height 2, resulting in an area of 2x2.\n- Finally, at column 2 with a base height of 0, there\'s only one column that fulfills this, resulting in an area of 0.\n\nTherefore, the maximum area achievable with rearranged columns to create a submatrix of consecutive 1s is 4."\n\n**Code : [C++]**\n```\nclass Solution \n{\npublic:\n    int largestSubmatrix(vector<vector<int>>& matrix) \n    {\n        ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);\n    \n        int m = matrix.size(), n = matrix[0].size();int ans = 0;\n        \n        for (int x = 0; x<m; x++)\n        {\n            for(int y = 0; y<n; y++)\n                if(matrix[x][y] != 0 && x > 0)\n                    matrix[x][y] += matrix[x-1][y];\n            \n            vector<int> height = matrix[x]; sort(height.begin(), height.end());\n            \n            for(int i=0; i<n;i++) ans = max(ans, height[i] * (n-i));\n        }\n        return ans;\n    }\n};\n\n//Please Upvote\n```\n![image](https://assets.leetcode.com/users/images/a07c1fd3-f8e3-4a61-a4dd-637e42ee2a7f_1700990894.578035.png)\n\n\n![image](https://assets.leetcode.com/users/images/3582f05c-5123-4cf1-ab08-f26a97ba7a7c_1700990873.8753545.jpeg)\n
['C', 'Sorting']