Tricky BomberMan HackerRank Problem on top of "Academics"

 So it's is 1:40 a.m., and I am trying to debug this somewhat dubious problem of HackerRank which is of medium level and is kinda sinuos. It is based on the questions having states, but I just can't figure out the conditions for the remaining states of grid and state1.

Well, I had figured out what to do till there, but now that I am stuck I would be thinking about this problem and may take a new one, along the way. Also I have to study academics, it's a hell and those subjects hurt both my brain and my soul, but any port in a storm.

Well this is my current state in this particular problem till now and I hope I would be able to resolve this by tomorrow:-

vector<string> bomberMan(int n, vector<string> grid) {
  int n_row=grid.size();
int n_column=grid[0].size();
vector<string> eS(n_row);

vector<string> state(grid);
string s="O";
for(int i=0;i<n_column-1;i++){
    s+="O";
}

for(int i=0;i<n_row;i++){
    eS[i]=s;
}

vector<string> state1(grid);
for(int i=0;i<n_row;i++){
    for(int j=0;j<n_column;j++){
        state[i][j]='O';
        state1[i][j]='O';
    }
}

for(int i=0;i<n_row;i++){
    for(int j=0;j<n_column;j++){
       
        if(grid[i][j]=='O'){
          state[i][j]='.';
            if(i!=0){
                state[i-1][j]='.';
            }
            if(i!=n_row-1){
                state[i+1][j]='.';
            }
            if(j!=n_column-1){
                state[i][j+1]='.';
            }
            if(j!=0){
                state[i][j-1]='.';
            }
        }
        
    }
}
for(int i=0;i<n_row;i++){
    for(int j=0;j<n_column;j++){
        if(state[i][j]=='O'){
              state1[i][j]='.';
              if(i!=0){
                state1[i-1][j]='.';
            }
            if(i!=n_row-1){
                state1[i+1][j]='.';
            }
            if(j!=n_column-1){
                state1[i][j+1]='.';
            }
            if(j!=0){
                state1[i][j-1]='.';
            }
        }
    }
}
cout<<"Displaying the state1 vector "<<endl;
for(string& st:state1){
    cout<<st<<endl;
}
cout<<"Displaying the state vector "<<endl;
for(string& s:state){
    cout<<s<<endl;
}
if(n==1){
    return grid;
}
if(n%2==0){
    return eS;
}
if(n%3==0){
    return state;
}

return state1;
}

Comments

Popular Posts