Simple logic start from the end points


#1
Comment body goes here.bool vis[1001][1001];
void dfs(int r,int c,vector<vector<char> > A){
    int n = A.size();
    vis[r][c] = 1;
    if(r+1 < n && !vis[r+1][c] && A[r+1][c] == 'O')
       dfs(r+1,c,A);
    if(r-1 >=0 && !vis[r-1][c] && A[r-1][c] == 'O')
       dfs(r-1,c,A);
    if(c+1 < A[0].size() && !vis[r][c+1] && A[r][c+1] == 'O')
       dfs(r,c+1,A);
    if(c-1 >= 0 && !vis[r][c-1] && A[r][c-1] == 'O')
       dfs(r,c-1,A);
    
}
void Solution::solve(vector<vector<char> > &A) {
   vector<pair<int,int> > v;
   int n = A.size();
   for(int i = 0;i<A[0].size();i++){
       if(A[0][i] == 'O')
         v.push_back({0,i});
       if(A[n-1][i] == 'O')
         v.push_back({n-1,i});
   }
   for(int i = 0;i<n;i++){
       if(A[i][0] == 'O')
          v.push_back({i,0});
       if(A[i][A[0].size()-1] == 'O')
          v.push_back({i,A[0].size()-1});  
   }
   for(int i = 0;i<n;i++){
       for(int j = 0;j<A[i].size();j++)
         vis[i][j] = false;
   }
  // cout<<v.size();
   for(int i = 0;i<v.size();i++){
       int r = v[i].first;
       int c = v[i].second;
       if(!vis[r][c]){
           dfs(r,c,A);
       }
   }
   for(int i = 0;i<n;i++){
       for(int j = 0;j<A[i].size();j++){
           if(vis[i][j] == 0)
             A[i][j] = 'X';
              
       }
   }
}