Pattern
Graphs
A graph holds things and the links between them. Walk it with depth-first or breadth-first search, and keep a record of what you have seen so you never loop. The usual cost is O(V + E), where V counts the things and E counts the links.
1. Number of Islandsgrid · graph · bfs · flood fillMed.2. Clone Graphgraph · bfs · hash mapMed.3. Max Area of Islandgrid · dfs · flood fillMed.4. Pacific Atlantic Water Flowgrid · bfs · multi-sourceMed.5. Surrounded Regionsgrid · bfs · borderMed.6. Rotting Orangesgrid · bfs · multi-sourceMed.7. Walls and Gatesgrid · bfs · multi-sourceMed.8. Course Schedulegraph · topological sort · cycleMed.9. Course Schedule IIgraph · topological sort · heapMed.10. Redundant Connectiongraph · union find · cycleMed.11. Number of Connected Componentsgraph · union find · componentsMed.12. Graph Valid Treegraph · tree · bfsMed.13. Word Laddergraph · bfs · stringsHard