30. Replace O's with X's
โ GFG solution to the Replace O's with X's problem: replace all 'O' surrounded by 'X' using boundary traversal and DFS/BFS techniques. ๐
๐งฉ Problem Description
๐ Examples
Example 1
Input:
grid[][] = [['X', 'X', 'X', 'X'],
['X', 'O', 'X', 'X'],
['X', 'O', 'O', 'X'],
['X', 'O', 'X', 'X'],
['X', 'X', 'O', 'O']]
Output:
[['X', 'X', 'X', 'X'],
['X', 'X', 'X', 'X'],
['X', 'X', 'X', 'X'],
['X', 'X', 'X', 'X'],
['X', 'X', 'O', 'O']]
Explanation: We only changed those 'O' that are surrounded by 'X'Example 2
Example 3
๐ Constraints
โ
My Approach
Boundary DFS Marking
๐ Time and Auxiliary Space Complexity
๐งโ๐ป Code (C++)
โ Code (Java)
๐ Code (Python)
๐ง Contribution and Support
๐Visitor Count
Last updated