Given an integer n representing the number of nodes labeled from 0 to n-1, and a 2D integer array edges where edges[i] = [ui, vi] represents an undirected edge between nodes ui and vi, return the minimum number of edges to traverse to reach a target node from a starting node. If no path exists between the start and target, return -1.
Explanation: The path from 0 to 4 is 0->1->2->3->4, which consists of 4 edges.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak