Depth-First Search pattern

Surrounded Regions

Given a grid of X and O cells, flip to X every region of O cells that is fully surrounded, that is, any region not connected 4-directionally to an O on the grid border. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 130
  • Medium
  • 1 approach

Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.

Depth-First SearchLeetCode 130

Medium

The approach

  1. 01 Border flood + capture sweep O(R·C)O(R·C) space
Played step by step, with its time and space.

What you will learn

  • How to read Surrounded Regions and spot the depth-first search pattern in it
  • Border flood + capture sweep: O(R·C) time, O(R·C) space
  • The pseudocode for each approach, its line lit as the animation runs
  • Practice: write your own pseudocode and get it checked

More Depth-First Search

See Surrounded Regions run, step by step

Sign in and this page opens on the animation, with all 18 Depth-First Search problems beside it.

DSA comes with the all labs plan and every ChaiCode batch.