Surrounded Regions
Capture all regions of O that are completely surrounded by X.
Examples
Input: ["XXXX","XOOX","XXOX","XOXX"]
Output: ["XXXX","XXXX","XXXX","XOXX"]
Input: ["X"]
Output: ["X"]
Hints
Start BFS/DFS from all border 'O's to mark all 'O's connected to the border as safe.
After marking, iterate through the entire board and flip all remaining 'O's (not marked as safe) to 'X'.
Use a queue for BFS or a stack for DFS to efficiently traverse and mark safe 'O's, ensuring optimal time complexity.
Related Problems
Surrounded Regions
Capture all regions of O that are completely surrounded by X.