WORLD 6
GRAPHS
Grids, dependencies and travel times: search outward, put steps in order, find the fastest route.
STAGE 0 Graphs tutorial
0:00 / 0:00
The move
Explore outward from a start. Breadth-first search uses a queue and ripples out ring by ring (fewest steps); depth-first search dives deep with a stack or recursion. Mark every node you visit so you never loop.
- Spot it
- The problem says connected, neighbours, islands, network, path, prerequisites or fewest steps. A grid is a graph too.
- Cost
- Each node and edge is handled once: O(V + E) time and O(V) space for the visited set.
21 STAGES
☆☆☆☆☆ Clear any 5 stages to beat this world, or all 21 for 100%.
MEDIUM1:59Number of Islands
Grid searchLC 200▶ START
MEDIUM1:58Number of Provinces
Depth-first searchLC 547▶ START
MEDIUM2:04Is Graph Bipartite?
Breadth-first searchLC 785▶ START
MEDIUM2:07Rotting Oranges
Breadth-first searchLC 994▶ START
MEDIUM2:07Snakes and Ladders
Breadth-first searchLC 909▶ START
MEDIUM2:10Shortest Path in Binary Matrix
Breadth-first searchLC 1091▶ START
MEDIUM2:00Pacific Atlantic Water Flow
Grid searchLC 417▶ START
MEDIUM2:03Surrounded Regions
Grid searchLC 130▶ START
HARD2:09Longest Increasing Path in a Matrix
Grid searchLC 329▶ START
MEDIUM1:58Clone Graph
Depth-first searchLC 133▶ START
MEDIUM2:04Course Schedule
Topological sortLC 207▶ START
MEDIUM2:10Course Schedule II
Topological sortLC 210▶ START
MEDIUM2:07Network Delay Time
Shortest pathLC 743▶ START
MEDIUM2:10Path With Minimum Effort
Shortest pathLC 1631▶ START
MEDIUM2:08Cheapest Flights Within K Stops
Shortest pathLC 787▶ START
HARD1:54Swim in Rising Water
Shortest pathLC 778▶ START
HARD2:09Reconstruct Itinerary
Eulerian pathLC 332▶ START
MEDIUM2:03Redundant Connection
Union-findLC 684▶ START
HARD2:08Critical Connections in a Network
Depth-first searchLC 1192▶ START
MEDIUM2:08Min Cost to Connect All Points
Minimum spanning treeLC 1584▶ START
HARD2:08Word Ladder
Breadth-first searchLC 127▶ START