Leetcode 3534. Path Existence Queries in a Graph II
Given n and array nums, build an undirected unweighted graph where an edge exists between i and j iff |nums[i] - nums[j]| ≤ maxDiff, and answer many queries asking the shortest path length (or -1 if unreachable) between specified node pairs. The core challenge is to compute distances efficiently for up to 1e5 nodes/queries without explicitly building the potentially dense O(n^2) graph by exploiting the value-proximity structure.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
0
Hello Interview Premium
Your account is free and you can post anonymously if you choose.