#1828
Medium Algorithms Queries on number of points inside a circle
Array Math Geometry
86.8% acceptance
Feb 25, 2026
1194
90
You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane. Multiple points can have the same coordinates.
You are also given an array queries where queries[j] = [xj, yj, rj] describes a circle centered at (xj, yj) with a radius of rj.
For each query queries[j], compute the number of points inside the jth circle. Points on the border of the circle are considered inside.
Return an array answer, where answer[j] is the answer to the jth query.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn count_points(points: Vec<Vec<i32>>, queries: Vec<Vec<i32>>) -> Vec<i32> {
queries.iter().map(|q| {
let (cx, cy, r) = (q[0], q[1], q[2]);
points.iter().filter(|p| {
let dx = p[0] - cx;
let dy = p[1] - cy;
dx * dx + dy * dy <= r * r
}).count() as i32
}).collect()
}
}