Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Surrounded Regions

Medium

Topics
GraphDFSBFSMatrix

Given an m x n board of 'X' and 'O', capture all regions of 'O' that are fully surrounded by 'X' (flip them to 'X'). Any 'O' connected to the border is safe. Return the resulting board.

Example 1

Input:  board = ["XXXX","XOOX","XXOX","XOXX"]
Output: ["XXXX","XXXX","XXXX","XOXX"]

Constraints

  • 1 <= m, n <= 200
  • board[i][j] is 'X' or 'O'.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access