Ctrl K

Devices in Router Range

Medium
An office floor plan marks devices: devices[i] = [x, y] is where the i-th device stands. Several devices may share the same spot. There is also a list of routers: routers[j] = [x, y, r] is a router at (x, y) that reaches anything at distance at most r. A device exactly r away is still in range. For each router, count the devices within its range, and return those counts in router order.
Example 1
devices=[[0, 0], [2, 0], [3, 4]], routers=[[0, 0, 2], [0, 0, 5]] → [2, 3]

The first router, range 2, reaches [0, 0] and [2, 0], which is exactly on the edge. The second, range 5, covers all three: [3, 4] is exactly 5 away.

Example 2
devices=[[1, 1], [1, 1]], routers=[[2, 2, 1]] → [0]

Both devices share one spot, but it is √2 > 1 away, so the router reaches neither.

Constraints
  • 1 ≤ devices.length ≤ 500
  • devices[i].length == 2, 0 ≤ x, y ≤ 500
  • 1 ≤ routers.length ≤ 500
  • routers[j].length == 3, 0 ≤ x, y ≤ 500, 1 ≤ r ≤ 500
  • All coordinates are integers
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNo Inward Corners MediumSmallest Paddock MediumSmallest Rectangle of Pins MediumNearest Points to the Base MediumLongest Firework Chain Medium
loading Python…
Input
devices=[[0, 0], [2, 0], [3, 4]], routers=[[0, 0, 2], [0, 0, 5]]
Expected
[2, 3]

Run checks the first 3 tests in your browser. Submit checks all 48 tests on the server, hidden ones included.