dsa1 min read
Jump Game III — BFS/DFS Reachability
Check if you can reach a 0 in the array by jumping arr[i] steps left or right. BFS/DFS from start index.
Read →
webcoderspeed.com
1276 articles
Check if you can reach a 0 in the array by jumping arr[i] steps left or right. BFS/DFS from start index.
Determine if you can finish all courses given prerequisites. Equivalent to detecting a cycle in a directed graph using BFS (Kahn) or DFS coloring.
Return a valid course order given prerequisites. Kahn's BFS topological sort outputs nodes in processing order — that is the valid schedule.
Check if n nodes and edges form a valid tree: must be connected and acyclic. Exactly n-1 edges, all connected via BFS/DFS or Union-Find.
Count connected components in an undirected graph. Union-Find or BFS both give O(V+E) solution.