id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 1 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n int m=board.size();\n int n=board[0].size();\n queue<pair<int,int>>q;\n vector<vector<bool>>vis(m,vector<bool>(n,0));\n for(int j=0; j<n; j++){\n if(board[0][j]=='O'){\n q... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dir = {{0,1},{1,0},{0,-1},{-1,0}};\n void solve(vector<vector<char>>& board) {\n int n = board.size();\n int m = board[0].size();\n vector<vector<bool>> vis(n,vector<bool>(m,false));\n for(int i=0;i<n;i++) {\n for(... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 1 | {
"code": "class Solution {\npublic:\n\n void dfs(int row,int col,vector<vector<char>>&board,vector<vector<int>>&vis){\n vis[row][col]=1;\n int drow[]={1,0,-1,0};\n int dcol[]={0,1,0,-1};\n for(int i=0;i<4;i++){\n int nrow=row+drow[i];\n int ncol=col+dcol[i];\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 1 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<char>>& board,vector<vector<bool>>& visited,int source,int end){\n if(source<0 or source>=board.size() or end<0 or end>=board[0].size() or visited[source][end] or board[source][end]!='O') return;\n visited[source][end] = true;\n dfs... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 2 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n int m = board.size();\n int n = board[0].size();\n vector<vector<int>> vis(m, vector<int>(n, 0));\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (board[i][j... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 2 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n int n = board.size();\n int m = board[0].size();\n vector<vector<int>> vis(n,vector<int> (m,0));\n queue<pair<int,int>> q;\n for(int j=0;j<m;j++)\n {\n if(board[0][j]=='O'){\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>> vis(n, vector<int>(m, 0));\n queue<pair<int, int>> q;\n for(int j=0; j<m; j++){\n if(grid[0][j] == 'O'){\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n bool isValid(int i, int j, int m, int n)\n {\n if(i<0 || j<0 || i>=m || j>=n)\n return false;\n return true;\n }\n void freed(int i, int j, vector<vector<char>>& board)\n {\n int m=board.size(), n=board[0].size();\n board[i][j]='... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n\n for (int i = 0; i < board.size(); ++i) {\n if (board[i][0] == 'O')\n dfs(board, i, 0);\n if (board[i][board[i].size() - 1] == 'O')\n dfs(board, i, board[i].size() - 1);\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\nprivate:\n void dfs(vector<vector<char>>& board, int x, int y, vector<vector<int>>& vis){\n int m = board.size(), n = board[0].size();\n \n board[x][y] = 'Y';\n vis[x][y] = 1;\n \n vector<pair<int, int>> dirs = {{0,-1},{0,1},{-1,0},{1,0}};\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n vector < vector < int > > dir;\n\n void dfs(int x, int y, int n, int m, vector < vector < char > > &v) {\n v[x][y] = 'M';\n for (auto p: dir) {\n int nx = x + p[0];\n int ny = y + p[1];\n\n if (nx >= 0 and ny >= 0 and nx < n a... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\n void dfs(vector<vector<int>> &visited, vector<vector<char>>&board , int i, int j)\n {\n visited[i][j]=1;\n int n = board.size();\n int m = board[0].size();\n vector<int> delrow={-1,0,0,1};\n vector<int> delcol={0,-1,1,0};\n for(int k=0;k<4;k++)... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\n void dfs(vector<vector<int>> &visited, vector<vector<char>>&board , int i, int j)\n {\n visited[i][j]=1;\n int n = board.size();\n int m = board[0].size();\n vector<int> delrow={-1,0,0,1};\n vector<int> delcol={0,-1,1,0};\n for(int k=0;k<4;k++)... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\nprivate:\nvoid bfs(vector<vector<char>>& board,vector<vector<int>>& vis,int x,int y)\n{\n queue<pair<int,int>> q;\n q.push({x,y});\n int row[]={-1,0,+1,0};\n int column[]={0,-1,0,+1};\n while(!q.empty())\n {\n x=q.front().first;\n y=q.front().second;\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void bfs(vector<vector<char>>& board,int i, int j,vector<vector<int>> &vis){\n int m = board.size();\n int n = board[0].size();\n queue<pair<int,int>> q;\n vector<pair<int,int>> v;\n q.push({i,j}); \n vis[i][j] = 1;\n int dx[4]... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\nprivate:\n void bfs(vector<vector<char>>& board, vector<vector<int>>& vis, int row,\n int col) {\n queue<pair<int, int>> q;\n q.push({row, col});\n vis[row][col] = 1;\n\n int rows[] = {0, -1, 0, 1};\n int cols[] = {-1, 0, 1, 0};\n\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\nprivate:\n void bfs(vector<vector<char>>& board, vector<vector<int>>& vis, int row,\n int col) {\n queue<pair<int, int>> q;\n q.push({row, col});\n vis[row][col] = 1;\n\n int rows[] = {0, -1, 0, 1};\n int cols[] = {-1, 0, 1, 0};\n\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n int rows, cols;\n vector<vector<bool>> visited;\n vector<pair<int, int>> directions = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};\n void bfs(int r, int c, vector<vector<char>>& board) {\n vector<pair<int, int>> coords;\n queue<pair<int, int>> q;\n q.push... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n int rows, cols;\n vector<vector<bool>> visited;\n vector<pair<int, int>> directions = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};\n void bfs(int r, int c, vector<vector<char>>& board) {\n vector<pair<int, int>> coords;\n queue<pair<int, int>> q;\n q.push... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\nvoid dfs(int row, int col, vector<vector<int>> &vis,vector<vector<char>> &mat,vector<int>delrow, vector<int>delcol) {\n vis[row][col] = 1; \n int n = mat.size();\n int m = mat[0].size();\n for(int i = 0;i<4;i++) {\n int nrow = row + delrow[i... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void bfs1(vector<vector<char>>& board,vector<vector<int>>& vis,int i,int j){\n int n = board.size();\n int m = board[0].size();\n vis[i][j] = 1;\n vector<pair<int,int>>direction{{-1,0},{1,0},{0,1},{0,-1}};\n queue<pair<int,int>>q;\n q... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n\n void bfs(int r , int c , vector<vector<char>>&board , vector<vector<int>>&vis , vector<int>delRow , vector<int>delCol){\n int n = board.size();\n int m = board[0].size();\n vis[r][c] = 1;\n\n for(int i=0;i<4;i++){\n int row = r+delRow[... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "/*\nIf a region of 'O' never touches an edge it will be captured\n*/\nclass Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n queue<pair<int, int>> regQ;\n queue<pair<int, int>> checkQ;\n vector<vector<int>> visited(board.size(), vector<int>(board[0].size(), 0));\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n\n void oMarker(int r,int c,vector<vector<char>>& board,vector<vector<bool>>& vis) {\n int n=board.size(),m=board[0].size();\n queue<pair<int,int>> q;\n q.push({r,c});\n vis[r][c]=true;\n\n while(!q.empty()) {\n vector<int> I={1,0,... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<char>>& board, int row, int col, vector<vector<char>> &ans,vector<vector<bool>> &vis){\n vis[row][col] = true;\n\n vector<int> delrow{0,1,0,-1};\n vector<int> delcol{-1,0,1,0};\n\n for(int i=0;i<4;i++){\n int nrow ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n if(board.empty() || board[0].empty())\n {\n return;\n }\n\n for(int i = 0; i < board.size(); i++)\n {\n for(int j = 0; j < board[0].size(); j++)\n {\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n int rows;\n int cols;\n void solve(vector<vector<char>>& board) {\n // get rows & cols size\n rows = board[0].size();\n cols = board.size();\n // have another function which is dfs, this will change the border(play with limits) connected O to... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\n vector<pair<int, int>> DIRS = {{1,0}, {-1,0}, {0,1}, {0,-1}};\npublic:\n // checks if indices are within given bounds\n // fact: if a cell has an out of bounds neighbour then is must be on the edge\n // use this to determine if O region is capturable\n bool isInBound... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\nprivate:\n int m;\n int n;\npublic:\n void isSafe(vector<vector<char>>& board, int i, int j, bool& saved) {\n if (board[i][j] != 'O' && !(board[i][j] == 'Z' && saved))\n return;\n \n if (!saved)\n if (i == 0 || j == 0 || i == m-1 || j ==... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\nprivate:\n int ROWS;\n int COLS;\n void BFS(vector<vector<char>>& board, int row, int col) {\n queue<pair<int, int>> q;\n q.push(make_pair(row, col));\n while (q.size() > 0) {\n auto front = q.front();\n int row = front.first, col = fron... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\ntypedef pair<int, int> P;\n P find(P i, map<P, P>& parent){\n if( parent[i] == i){\n return i;\n }\n\n return parent[i] = find(parent[i], parent);\n }\n\n void Union(P a, P b, map<P, P>& parent, int& n, int& m){\n P a_parent = find(... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\n public:\n const static int N = 205;\n bool vis[N][N];\n vector<pair<int, int>> fr = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};\n\n int n, m;\n vector<vector<char>> *v;\n\n bool valid(int i, int j) {\n return !(i < 0 || i >= n || j < 0 || j >= m || (*v)[i][j] == 'X' ||... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\n unordered_set<int> visited;\n int M = 0;\n int N = 0;\n void mark(vector<vector<char>>& board, int r, int c) {\n if (r < 0 || c < 0 || r == M || c == N || board[r][c] == 'X') {\n return;\n }\n auto id = r * N + c;\n if (visited.count(id)... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void change(vector<vector<char>>& board, int k , int j )\n { board[k][j]='*';\n vector<vector<int>>dir={{-1,0},{1,0},{0,1},{0,-1}};\n for(int i =0 ; i<4 ; i++){\n int x= k+ dir[i][0];\n int y= j+ dir[i][1];\n if(x>=0 &... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int,int>> dirs{{0,1},{0,-1},{1,0},{-1,0}};\n void solve(vector<vector<char>>& board) {\n for(int i = 0; i < board.size(); i++)\n {\n for(int j = 0; j < board[0].size(); j++)\n {\n if(i == 0 || j == 0 || i == bo... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<char>>&grid,int r,int c)\n {\n grid[r][c]='K';\n\n vector<vector<int>> dir = {{1,0},{0,1},{-1,0},{0,-1}};\n int n = grid.size();\n int m = grid[0].size();\n for(int i=0;i<4;i++)\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\nprivate:\n static constexpr int dr[] = {-1, +1, 0, 0};\n static constexpr int dc[] = {0, 0, -1, +1};\n int n, m;\n int vis[202][202], vis2[202][202];\n \n bool isValidCell(int r, int c) {\n return ( 0 <= r && r < n && 0 <= c && c < m );\n }\n \n bool isNo... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] = {1, 0, -1, 0};\n int dy[4] = {0, -1, 0, 1};\n\n bool check(int i, int j, int n, int m) {\n return i < n && j < m && i >= 0 && j >= 0;\n }\n\n void dfs(int i, int j, vector<vector<char>> &grid, vector<vector<int>> &vis) {\n int n = grid.si... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] = {0, 0, 1, -1};\n int dy[4] = {-1, 1, 0, 0};\n void solve(vector<vector<char>>& board) {\n int m = board.size();\n int n = board[0].size();\n\n map <pair<int,int>, int> mp;\n vector <vector<int>> vis(m, vector <int> (n, 0));\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n int m=board.size(), n=board[0].size();\n int start=0, end=n-1;\n // for(int i=1; i<m-1; i++){\n // start=0, end=n-1;\n // while(board[i][start]!='X' && start<end) start++;\n // w... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n int m1,n1;\n vector<int> dx,dy;\n bool isBdry(int &x,int &y){\n return (x==0 || y==0 || x == m1 || y == n1);\n }\n bool isValid(int &x,int &y){\n return (x>=0 && y>=0 && x<=m1 && y<=n1);\n }\n bool isCaptured(int i,int j,vector<vector<char>>& b... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<char>>& board, int i, int j) {\n if (i < 0 || i >= board.size() || j < 0 || j >= board[0].size() || board[i][j] != 'O') return;\n board[i][j] = '#';\n vector<vector<int>> dirs = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};\n for (auto... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>> &board) {\n int m = board.size();\n int n = board[0].size();\n vector<vector<bool>> visited(m, vector<bool>(n, false));\n for (int i = 0; i < m; ++i) {\n for (int j = 0; j < n; ++j) {\n if (... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int row , int col , vector<vector<char>>& board ,bool flag){\n\n int n = board.size();\n int m = board[0].size();\n\n if( flag==true && row < 0 || row>=n || col>=m || col < 0 || board[row][col] == 'X' || board[row][col] == '1'){\n ret... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n bool dfs(int i, int j, vector<vector<char>>& board, vector<vector<int>>& vis, bool &flag){\n int n = board.size();\n int m = board[0].size();\n if(i==0 || i==n-1 || j==0 || j==m-1){\n flag = false;\n }\n vis[i][j] =1;\n int... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n \n int dx[4]={0,0,-1,1};\n int dy[4]={-1,1,0,0};\n void Fun(vector<vector<char>>&board,int i,int j,int n,int m,vector<vector<int>>&vis,int &flag){\n \n for(int k=0;k<4;k++){\n int row=i+dx[k];\n int col=j+dy[k];\n if(row>=0 && col>=0 ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n int m=board.size(), n=board[0].size();\n for(int i=1; i<m-1 ; i++){\n for(int j=1; j<n-1; j++){\n if(board[i][j]!='X' && board[i][j]!='Y'){\n if(isRegionValid(board, i, j)){... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n bool isSafe(int r , int c , int m , int n)\n {\n return (r >=0 && r < m && c >=0 && c< n); \n }\n void floodFill(int r , int c , int m , int n , vector<vector<char>>&board)\n {\n board[r][c] = 'V';\n\n vector<vector<int>> dirs = {{-1,0} , {1 ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n uint m = board.size();\n uint n = board[0].size();\n array<bitset<300>, 300> visited;\n vector<tuple<int, int>> region;\n queue<tuple<int, int>> q;\n\n auto process = [&]() {\n //... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n int vis[201][201];\n void reset(){\n for(int i = 0; i < 201; i++){\n for(int j = 0; j < 201; j++) vis[i][j] = 0;\n }\n }\n vector<pair<int, int>> movements = {\n {0, 1}, {1, 0}, {-1, 0}, {0, -1}\n };\n bool valid(int r, int c, in... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n\n\n vector<vector<int>> vis1,vis2;\n vector<vector<char>> arr;\n int n,m;\n\n bool check(int x,int y){\n if(min(x,y)<0 || x>=n || y>=m)\n return false;\n return true;\n }\n\n int dx[4]={1,0,-1,0};\n int dy[4]={0,-1,0,1};\n\n void ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n uint m = board.size();\n uint n = board[0].size();\n array<bitset<300>, 300> visited;\n vector<tuple<int, int>> region;\n queue<tuple<int, int>> q;\n\n auto process = [&]() {\n bo... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n int m = board.size(), n = board[0].size();\n for (int i = 0; i < m; i++) {\n dfs(board, i, 0, 'O', 'F');\n dfs(board, i, n - 1, 'O', 'F');\n }\n for (int j = 0; j < n; j++) {\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n\n void convert(vector<vector<char>>& board, char c1, char c2, int i, int j) {\n if (i < 0 || i >= board.size() || j < 0 || j >= board[0].size() || board[i][j] != c1) {\n return;\n }\n board[i][j] = c2;\n convert(board, c1, c2, i - 1, j);... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<char>>& A, int i, int j, int m, int n) {\n if(i < 0 || i >= m || j < 0 || j >= n || A[i][j] != 'O') return;\n A[i][j] = '#'; // Temporarily mark the 'O' cells connected to the boundary\n vector<int> a = {1, -1, 0, 0}, b = {0, 0, 1, ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<char>>& board, int line, int col, vector<int>& visited, bool isOnEdge)\n {\n int m = board.size();\n int n = board[0].size();\n if (line < 0 || line >= m || col < 0 || col >= n || board[line][col] == 'X')\n return;\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<char>>& board, int line, int col, vector<int>& visited, bool isOnEdge)\n {\n int m = board.size();\n int n = board[0].size();\n if (line < 0 || line >= m || col < 0 || col >= n || board[line][col] == 'X')\n return;\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n int m = board.size(), n = board[0].size();\n vector<vector<int>> visited(m, vector<int>(n, 0));\n for (int i = 0; i < m; i++){\n for (int j = 0; j < n; j++){\n //if (i == 3 && j == 3) ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n \n for(int r = 0; r < board.size(); ++r){\n for(int c = 0; c < board[0].size(); ++c){\n bool isEdge = r == 0 || r == board.size() - 1 || c == 0 || c == board[0].size() - 1 ? true : false;\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n\n int m = board.size();\n int n = board[0].size();\n\n vector<vector<bool>> visited(m, vector<bool>(n, false));\n\n for (int i = 0; i < n; i++) {\n dfs(board, 0, i, true, visited);\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n bool isSorrounded(vector<vector<char>>& b,vector<vector<int>>& vis,int i,int j,int r ,int c)\n {\n if(i>=r||i<0||j>=c||j<0) return false;\n if(vis[i][j]==1||b[i][j]=='X') return true;\n vis[i][j]=1;\n bool f= isSorrounded(b,vis, i+1, j, r , c);\n f... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n auto n_row = board.size();\n auto n_col = board[0].size();\n //find an O\n for(int i = 1; i < n_row-1; ++i){\n for(int j = 1; j < n_col-1; ++j){\n if (board[i][j] == 'O'){\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n unordered_set<int> s; unordered_map<int, int> v;\n\n void bfs(int st, vector<vector<char>>& board) {\n int n = board.size(); int m = board[0].size();\n bool b = true; queue<int> q; q.push(st); s.insert(st); v[st] = 1;\n while(!q.empty()) {\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void travel(vector<vector<char>>& board, vector<vector<int>>& visited, int& curr, int& flag, int i, int j)\n {\n if(i<0 || i>=board.size() || j<0 || j>=board[0].size())\n {\n flag = 1; // marking that the region got safe\n return;\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n\n vector<vector<int>> adjacent_nodes(int i, int j, int m, int n){\n vector<vector<int>> ans;\n \n if (i > 0) ans.push_back({i - 1, j}); \n if (j > 0) ans.push_back({i, j - 1}); \n if (i < m - 1) ans.push_back({i + 1, j});\n if (j < n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n int edgectrl(vector<vector<char>>&board,int row,int col){\n if (row==0||col==0||row==board.size()-1||col==board[0].size()-1){\n return 0;\n } \n return 1;\n \n }\n void marker(vector<vector<char>>&board,int row,int col,int &mark){\n... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic: \n void set(vector<vector<char>>& board, int i, int j, vector<vector<int>>& vis, int m, int n, bool curr){\n if(i < 0 || j < 0 || i >= m || j >= n || vis[i][j] || board[i][j] == 'X') return;\n vis[i][j] = 1;\n if(curr) board[i][j] = '1';\n else board... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n vector<vector<char>> visited(board.size(), vector<char>(board[0].size(), 0));\n for (int i = 0; i < board.size(); ++i)\n for (int j = 0; j < board[i].size(); ++j)\n if (!visited[i][j] && board... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<char>>& board, map<pair<int,int>, bool>& vis, int i, int j)\n {\n int r = board.size(), c = board[0].size();\n if (i < 0 || j < 0 || i>= r || j >= c || vis[{i,j}])\n {\n return;\n }\n\n vis[{i,j}] = true;... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n\n set <pair<int,int>> visited = {}; \n\n void solve(vector<vector<char>>& board) {\n int rows = board.size();\n int cols = board[0].size();\n\n for (auto r=1; r<rows-1; r++) {\n for (auto c=1; c<cols-1; c++) {\n if (board[r][c... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n for(int i=0; i<board.size(); i++)\n {\n for(int j=0; j<board[0].size(); j++)\n {\n bool edge = false; \n if(board[i][j]=='O')\n {\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n\n void bfs(vector<vector<char>>& board, int i, int j, int m, int n) {\n deque<pair<int, int>> q;\n q.push_back(pair<int, int>(i, j));\n vector<pair<int, int>> region;\n vector<vector<bool>> visited(m, vector<bool>(n, false));\n while(q.size(... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n\n void bfs(vector<vector<char>>& board, int i, int j, int m, int n) {\n deque<pair<int, int>> q;\n q.push_back(pair<int, int>(i, j));\n vector<pair<int, int>> region;\n vector<vector<bool>> visited(m, vector<bool>(n, false));\n while(q.size(... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\n vector<vector<int>> vis; \npublic:\n void solve(vector<vector<char>>& grid) {\n int n = grid.size(); \n int m = grid[0].size(); \n\n vis.assign(n, vector<int>(m, 0)); \n for(int i=0; i<n; i++){\n for(int j=0; j<m; j++){\n if(gri... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n int board_r = board.size();\n int board_c = board[0].size();\n unordered_set<string> visited;\n vector<pair<int, int>> dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n vector<vector<pair<int, int>>> mo... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<int, int> id;\n unordered_map<int, bool> border;\n unordered_map<int, int> sz;\n\n int find(int p){\n int root = p;\n while(id[root] != root){\n root = id[root];\n }\n while(p != root){\n int next = id[p... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n set<pair<int,int>> visited;\n set<pair<int,int>> marked;\n void bfs(int x, int y, vector<vector<char>>& board){\n marked.clear();\n marked.insert({x,y});\n board[x][y] = 'X';\n queue<pair<int,int>> q;\n q.push({x,y});\n visited.... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n set<pair<int,int>> visited;\n set<pair<int,int>> marked;\n void bfs(int x, int y, vector<vector<char>>& board){\n marked.clear();\n marked.insert({x,y});\n board[x][y] = 'X';\n queue<pair<int,int>> q;\n q.push({x,y});\n visited.... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n set<pair<int,int>> visited;\n set<pair<int,int>> marked;\n void bfs(int x, int y, vector<vector<char>>& board){\n marked.clear();\n marked.insert({x,y});\n board[x][y] = 'X';\n queue<pair<int,int>> q;\n q.push({x,y});\n visited.... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n int bfs(vector<vector<char>>&board, vector<vector<int>>&visited, int i, int j, set<pair<int, int>> &temp){\n int m = board.size();\n int n = board[0].size();\n queue<pair<int, int>> q;\n int flag = 0;\n\n q.push({i,j});\n temp.insert(... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<char>>& board) {\n int n = board.size();\n if (n == 0) return;\n int m = board[0].size();\n\n for (int i = 0; i < n; ++i) \n for (int j = 0; j < m; ++j) \n {\n if(board[i][j]=='O') \n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n\n bool isValid(pair<int,int>p,int n,int m)\n { \n int x = p.first;\n int y = p.second;\n return (x>=0 && y>=0 && x<n && y<m);\n }\n\n void bfs(pair<int,int>start,set<pair<int,int>>&visited,vector<vector<char>>& board,int n,int m,vector<int>move... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\n bool f[201][201], d;\n vector<pair<int,int>> v;\n int n, m;\n void df(int a, int b, vector<vector<char>>& board){\n f[a][b] = 1;\n if(a==0 || a==n || b==0 || b==m) d=1;\n v.push_back(make_pair(a, b));\n if((a+1)<=n && f[a+1][b] == 0 && board[a+1][b... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\nprivate:\n void dfs(int row,int col,vector<vector<int>>& visited,\n vector<vector<char>>& board, bool switched){\n visited[row][col] = 1;\n\n if(switched) board[row][col] = 'X';\n\n int r[] = {0,0,-1,1};\n int c[] = {-1,1,0,0};\n\n int n = board.si... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] = {-1, 0, 0, 1};\n int dy[4] = {0, -1, 1, 0};\n\n vector<pair<int,int>> notebook;\n int vis[201][201];\n\n // jo jo components x, y se connected hai\n // umne ye check karo ki koi edge par hai ya nahi\n bool dfs(int x, int y,vector<vector<char>>& b... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<char>>& board, int i, int j) {\n vector<pair<int, int>> dir{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n stack<pair<int, int>> s;\n vector<pair<int, int>> convertedRegion;\n s.push(make_pair(i, j));\n int borderRight = board[0... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\nprivate:\n bool\n getRegion(vector<vector<char>>& board, bool**& visited, int i, int j, vector<tuple<int,int>>& region)\n {\n if(i >= board.size())\n return false;\n\n if(j >= board[i].size())\n return false;\n\n if(visited[i][j])\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void DFS(vector<vector<char>>& board, vector<vector<int>>& vis, int r,\n int c, queue<pair<int, int>>& q) {\n int drow[] = {0, -1, 0, 1};\n int dcol[] = {-1, 0, 1, 0};\n for (int i = 0; i < 4; i++) {\n int newr = r + drow[i];\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\nprivate:\n bool\n getRegion(vector<vector<char>>& board, bool**& visited, int i, int j, vector<tuple<int,int>>& region)\n {\n if(i >= board.size())\n return false;\n\n if(j >= board[i].size())\n return false;\n\n if(visited[i][j])\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void makeX(int i, int j, vector<vector<char>>& mat, vector<vector<int>>& visited){\n mat[i][j] = 'X';\n visited[i][j] = 1;\n if(!visited[i+1][j] && mat[i+1][j] == 'O') makeX(i+1, j, mat, visited);\n if(!visited[i][j+1] && mat[i][j+1] == 'O') makeX(... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> color;\n bool isSurr(int i, int j, vector<vector<char>>& board, char c, int cl) {\n color[i][j] = cl + 1;\n board[i][j] = c;\n bool flag = i == 0 || i == color.size() - 1 || j == 0 || j == color[0].size() - 1;\n cout << \"i: ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n pair<int,int> directions[4] = {{0,1},{1,0},{0,-1},{-1,0}};\n \n bool check(int x, int y, vector<vector<char>>& grid, vector<pair<int,int>>& path) {\n if (x == 0 || x == grid.size() - 1 || y == 0 || y == grid[0].size() - 1) {\n return false;\n }\... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n pair<int,int> directions[4] = {{0,1},{1,0},{0,-1},{-1,0}};\n \n bool check(int x, int y, vector<vector<char>>& grid, vector<pair<int,int>>& path) {\n if (x == 0 || x == grid.size() - 1 || y == 0 || y == grid[0].size() - 1) {\n return false;\n }\... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n pair<int,int> directions[4] = {{0,1},{1,0},{0,-1},{-1,0}};\n \n bool check(int x, int y, vector<vector<char>>& grid, vector<pair<int,int>>& path) {\n if (x == 0 || x == grid.size() - 1 || y == 0 || y == grid[0].size() - 1) {\n return false;\n }\... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\n void dfs(int i, int j, vector<vector<char>>& board, vector<vector<int>>& visited, bool& flag){\n if(i < 0 || j < 0 || i >= board.size() || j >= board[0].size() || board[i][j] == 'X' || visited[i][j]){\n return;\n }\n if(i == 0 || j == 0 || i == board.si... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n unordered_set<int> surround_mark;\n int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};\n int count = 0;\n void solve(vector<vector<char>>& board) {\n int m = board.size();\n int n = board[0].size();\n vector<vector<int>> visited(m, vector<int>(n, 0));\n... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int r, int c, bool mark, vector<vector<char>>& board, vector<vector<bool>>& visited) {\n // base cases: not 'O' or visited, leave\n if (board.at(r).at(c)!='O' or visited.at(r).at(c)) {\n return;\n }\n // process current node\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n void bfs1(int i, int j, vector<vector<char>>& landscape,\n map<vector<int>, int>& visited) {\n if (j + 1 <= landscape[i].size() - 1 && landscape[i][j + 1] == 'O' &&\n visited.count({i, j + 1}) == 0) {\n visited[{i, j + 1}] = 1;\n ... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\n constexpr static int dirs[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n vector<vector<bool>> discarded;\n\n void discard_region(vector<vector<char>> &board, int row, int col) {\n if (board[row][col] == 'X' || discarded[row][col])\n return;\n else {\n discarded[row][col]... |
130 | <p>You are given an <code>m x n</code> matrix <code>board</code> containing <strong>letters</strong> <code>'X'</code> and <code>'O'</code>, <strong>capture regions</strong> that are <strong>surrounded</strong>:</p>
<ul>
<li><strong>Connect</strong>: A cell is connected to adjacent cells horizontally o... | 3 | {
"code": "class Solution {\npublic:\n bool valid(vector<vector<char>>& board,vector<vector<int>> &vis,int i,int j ,int n,int m)\n {\n return (i<n && i>=0 && j<m && j>=0 && vis[i][j]==-1 && board[i][j]=='O');\n }\n bool dfs(vector<vector<char>>& board,vector<vector<int>> &vis,int i,int j ,int n,int... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.