Router Reachability Within Manhattan Range
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.