Check whether a path exists between two indices in a graph built from a sorted array.
Unlock detailed company stats for this questionUpgrade
Given a sorted array arr of size N and an integer diff, construct an undirected graph where each node represents an index. Connect nodes i and j if |arr[i] - arr[j]| <= diff. Given a list of queries [u, v], return a list of booleans indicating whether there is a path between u and v. Example: arr = [1, 2, 3, 6], diff = 2, queries = [[0, 2], [1, 3]] -> [True, False]. Follow-ups: what if the array is sorted in descending order; what if it is not sorted; which sorting algorithm would you use. Reported as a repeat question from previous interviews.
Expect follow-ups like
- What if the array is sorted in descending order?
- What if the input array is not sorted?
- Which sorting algorithm will you use?
Format · Google SWE4 screening, 45 minutes.
Community answers
No answers contributed by the community yet.


