DFS
Depth-first search on a 2D grid treats each cell as a node, with edges to its 4 neighbors (up, down, left, right). Starting from any unvisited cell, DFS explores as far as possible before backtracking.
Connected Components
A connected component in a grid is a maximal set of cells that are all reachable from each other via adjacent moves.
200. Number of Islands
419. Battleships in a Board
694. Number of Distinct Islands
Medium·
Solutions:
FIG. 694 NUMBER OF DISTINCT ISLANDS● INTERACTIVE
733. Flood Fill
1034. Coloring A Border
463. Island Perimeter
695. Max Area of Island
3619. Count Islands With Total Value Divisible by K
Medium·
Solutions:
FIG. 3619 COUNT ISLANDS DIVISIBLE● INTERACTIVE
1254. Number of Closed Islands
Medium·
Solutions:
FIG. 1254 NUMBER OF CLOSED ISLANDS● INTERACTIVE
1905. Count Sub Islands
827. Making A Large Island
Surrounded Regions
130. Surrounded Regions
417. Pacific Atlantic Water Flow
Medium·
Solutions:
FIG. 417 PACIFIC ATLANTIC WATER FLOW● INTERACTIVE