dsa1 min read
Shortest Bridge — DFS Find + BFS Expand
Find minimum flips to connect two islands. DFS to find and color first island, then BFS outward until reaching second island.
Read →
webcoderspeed.com
1276 articles
Find minimum flips to connect two islands. DFS to find and color first island, then BFS outward until reaching second island.
Find path from top-left to bottom-right minimizing maximum absolute difference between consecutive cells. Use Dijkstra or binary search + BFS.
Count islands after each addLand operation. Online version requires Union-Find: add each land cell and union with adjacent land cells.
Deep copy an undirected graph. BFS/DFS with a HashMap from original node to cloned node prevents revisiting and handles cycles.
Count connected components in an undirected graph given as adjacency matrix. DFS or Union-Find both work.