 # Easy and short cpp sol

#1

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;
}

#2

Superb and easy logic, Must be appreciated #3

Why are we sorting each column???

#4

Hey, plz explain ur logic. Thanks!

#5

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.

#6

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