Skip to main content
All Questions

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.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.