#3534
Path Existence Queries in a Graph II
international master · 2080 · lc hard +32 · 26.2% accepted · 52 likes · top 4%
Description
Construct an unweighted graph on n nodes using nums: add an edge between i and j when |nums[i] - nums[j]| <= maxDiff.
For each query [ui, vi], return the shortest path (hop count) between ui and vi, or -1 if unreachable.
Return the array of answers.
Code
1
2
3