Queries on Number of Points Inside a Circle
Real-world version: Sensors Within Each Scan RadiusThe statement here is our own: the same inputs, outputs and technique.
A survey grid carries fixed sensors. sensors[i] = [x, y] gives the integer coordinates of sensor i; two sensors may share a position.
A radar makes a series of circular sweeps. scans[j] = [x, y, r] describes a sweep centred at (x, y) with radius r. A sensor is covered by that sweep when its straight-line distance to the centre is at most r. A sensor lying exactly on the circle of radius r counts as covered.
Go through the sweeps in the order listed, work out how many sensors each one covers, and give back those totals as a single list. Two sensors on the same position are tallied separately.
Examples
Example 1
- Input
- sensors = [[7, 2], [2, 9], [10, 10], [6, 6]], scans = [[6, 3, 2], [9, 9, 3], [0, 0, 4]]
- Output
- [1, 1, 0]
The first sweep reaches sensor (7, 2), which sits a distance of about 1.41 from (6, 3). The second reaches sensor (10, 10), about 1.41 from (9, 9). The third covers no sensor at all, since the nearest is (6, 6) at about 8.49 from the origin.
Example 2
- Input
- sensors = [[3, 4], [0, 5], [4, 4]], scans = [[0, 0, 5]]
- Output
- [2]
Sensors (3, 4) and (0, 5) are both exactly 5 from the centre, so both count as covered. Sensor (4, 4) is about 5.66 away and is not.
Example 3
- Input
- sensors = [[2, 2], [2, 2], [7, 7]], scans = [[2, 2, 1], [7, 7, 9]]
- Output
- [2, 3]
The first sweep is centred on the position two sensors share, so it covers both of them. The second sweep has a radius of 9 and reaches all three sensors.
Constraints
- 1 <= sensors.length <= 500
- sensors[i].length == 2
- 0 <= sensors[i][j] <= 500
- 1 <= scans.length <= 500
- scans[j].length == 3
- 0 <= scans[i][j] <= 500
- Sweep j is [x_j, y_j, r_j] with 1 <= r_j <= 500.
- All coordinates and radii are integers.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def sensors_in_range(sensors: list[list[int]], scans: list[list[int]]) -> list[int]:public int[] sensorsInRange(int[][] sensors, int[][] scans)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 9 test cases: 9 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Largest Triangle AreaReal-world version: The Largest Triangle Between PegsEasy
- K Closest Points to OriginReal-world version: Nearest Survey StakesMedium
- Detonate the Maximum BombsReal-world version: Largest Chain of Quarry ChargesMedium
- Minimum Area Rectangle IIReal-world version: Smallest Slanted FrameMedium