Router Reachability Within Manhattan Range
Updated
Problem statement
Each router is a point [x,y]. Two routers can communicate directly when their Manhattan distance is at most range.
Given start and end router indices, return whether data can be relayed from start to end through any sequence of direct links.
All links are bidirectional. A router can always reach itself.
Function
canRoute(routers: int[][], range: int, start: int, end: int) → booleanExamples
Example 1
routers = [[0,0],[0,8],[10,8],[0,28]]range = 10start = 0end = 2return = trueRouter 0 reaches 1, and router 1 reaches 2.
Example 2
routers = [[0,0],[20,0]]range = 10start = 0end = 1return = falseThe only pair is outside range.
Example 3
routers = [[5,5]]range = 0start = 0end = 0return = trueA router reaches itself without a link.
Constraints
1 <= routers.length <= 2000.- Each router contains two coordinates in
[-10^9,10^9]. 0 <= range <= 2*10^9.- Start and end are valid indices.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Detonate Bombs with Chain ReactionsAirbnb · PHONE SCREENAirbnb interview questions
- Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Course ScheduleOracle · ONSITE INTERVIEWOracle interview questions
- Course SchedulePlaud · ONSITE INTERVIEW
- Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Nearest Charging Station on a GridSpotify · ONSITE INTERVIEW
- Hierarchical Permission CheckeBay · ONSITE INTERVIEWeBay interview questions
- Evaluate DivisionPhonePe · ONSITE INTERVIEWPhonePe interview questions
- Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Radar Barrier CrossingSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions