Given an m x n board of 'X' and 'O' characters, capture every region of 'O' that is completely surrounded by 'X' — meaning it has no connection to an 'O' on the border — by flipping it to 'X', in place.
board with an inner O-region fully enclosed by Xthe enclosed region is flipped to X; border-connected O's staySolve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →A graph models relationships as nodes and edges, which can be directed or undirected, weighted or not. Most graph problems come down to choosing the right traversal — DFS, BFS, or union-find — for what you're trying to find.
Original problem on LeetCode ↗