Fix the base vary vertex

int Solution::solve(vector<string> &A) {
int m=A.size();
if(m==0)
    return 0;
int n=A[0].size();
vector<vector<int>>base(n,vector<int>(3,0));
for(int i=0;i<n;i++){
    int r1=INT_MAX,g1=INT_MAX,b1=INT_MAX;
    for(int j=0;j<m;j++){
        if(A[j][i]=='r')
            r1=min(r1,j);
        else if(A[j][i]=='g')
            g1=min(g1,j);
        else if(A[j][i]=='b')
            b1=min(b1,j);
    }
    int r2=INT_MIN,g2=INT_MIN,b2=INT_MIN;
    for(int j=m-1;j>=0;j--){
        if(A[j][i]=='r')
            r2=max(r2,j);
        else if(A[j][i]=='g')
            g2=max(g2,j);
        else if(A[j][i]=='b')
            b2=max(b2,j);
    }
    if(r1!=INT_MAX && g2!=INT_MIN)
        base[i][0]=g2-r1+1;
    if(g1!=INT_MAX && r2!=INT_MIN)
        base[i][0]=max(base[i][0],r2-g1+1);
    if(r1!=INT_MAX && b2!=INT_MIN)
        base[i][1]=b2-r1+1;
    if(b1!=INT_MAX && r2!=INT_MIN)
        base[i][1]=max(base[i][1],r2-b1+1);
    if(g1!=INT_MAX && b2!=INT_MIN)
        base[i][2]=b2-g1+1;
    if(b1!=INT_MAX && g2!=INT_MIN)
        base[i][2]=max(base[i][2],g2-b1+1);

    
}
vector<vector<bool>>check(n,vector<bool>(3,false));
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
        if(A[j][i]=='r')
            check[i][0]=true;
        else if(A[j][i]=='g')
            check[i][1]=true;
        else if(A[j][i]=='b')
            check[i][2]=true;
    }
}
int area=0;
for(int i=0;i<n;i++){
    if(check[i][0]){
        for(int j=0;j<n;j++){
            area=max(area,(int)ceil(((abs(i-j)+1)*base[j][2])/2.0)); 
        }
    }
    if(check[i][1]){
        for(int j=0;j<n;j++){
            area=max(area,(int)ceil(((abs(i-j)+1)*base[j][1])/2.0)); 
        }
    }
    if(check[i][2]){
        for(int j=0;j<n;j++){
            area=max(area,(int)ceil(((abs(i-j)+1)*base[j][0])/2.0)); 
        }
    }
}
return area;

}

Click here to start solving coding interview questions