int Solution::solve(vector<vector > &A) {

for(int i=1;i<A.size();i++) //STORING THE COUNT OF CONSECUTIVE 1’S

for(int j=0;j<A[i].size();j++)

if(A[i][j]) A[i][j]+=A[i-1][j];

int res=0;

for(int i=0;i<A.size();i++){ //FIND COLWISE MAX AREA

sort(A[i].begin(),A[i].end(),greater());

for(int j=0;j<A[i].size();j++)res=max(res,A[i][j]*(j+1));}

return res;

}

# Easy and short cpp sol

**msbobby87**#1

We are not sorting each column rather we are sorting each row.

If your ques is why are we sorting each row ?

ans - because its given in the ques we can arrange each column in any order so by sorting the row in descending order we are actually making all the 1’s together. So after sorting each row we have the max COUNT of 1’s available in each cell considering all the 1’s above that cell if they are coonsicutive. Now if multiply this value of each cell with repect to its colums number which will be J+1 since j starts from 0.This way we can actually calculate the area as required in the ques.

A :

[

[1, 0, 1, 0, 0]

[1, 0, 1, 1, 1]

[1, 1, 1, 1, 1]

[1, 0, 0, 1, 0]

]

code fails on following test case