3532. Path Existence Queries in a Graph I
You are given an integer
nrepresenting the number of nodes in a graph, labeled from 0 ton - 1.You are also given an integer array
numsof lengthnsorted in non-decreasing order, and an integermaxDiff.An undirected edge exists between nodes
iandjif the absolute difference betweennums[i]andnums[j]is at mostmaxDiff(i.e.,|nums[i] - nums[j]| <= maxDiff).You are also given a 2D integer array
queries. For eachqueries[i] = [ui, vi], determine whether there exists a path between nodesuiandvi.Return a boolean array
answer, whereanswer[i]istrueif there exists a path betweenuiandviin theithquery andfalseotherwise.
1 | class Solution { |