#1828

Queries on Number of Points Inside a Circle

pupil · 385 · lc medium +24 · verified · 86.8% accepted · 1,194 likes · top 98%

Description

Given an array points where points[i] = [xi, yi] holds the 2D coordinates of the i-th point (duplicates allowed), and an array queries where each queries[j] = [xj, yj, rj] defines a circle centered at (xj, yj) with radius rj, count how many points lie inside or on the boundary of each circle.

Return an array answer where answer[j] is the count for the j-th query.

Example 1:

Input: points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]
Output: [3,2,2]
Explanation: The points and circles are shown above.
queries[0] is the green circle, queries[1] is the red circle, and queries[2] is the blue circle.

Example 2:

Input: points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]
Output: [2,3,2,4]
Explanation: The points and circles are shown above.
queries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is purple.

Code

1
2
3