1828. Queries on Number of Points Inside a Circle Medium

@problem@discussion
#Array#Math#Geometry



1/**
2 * [1828] Queries on Number of Points Inside a Circle
3 *
4 * You are given an array points where points[i] = [xi, yi] is the coordinates of the i^th point on a 2D plane. Multiple points can have the same coordinates.
5 * 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.
6 * For each query queries[j], compute the number of points inside the j^th circle. Points on the border of the circle are considered inside.
7 * Return an array answer, where answer[j] is the answer to the j^th query.
8 *  
9 * Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/25/chrome_2021-03-25_22-34-16.png" style="width: 500px; height: 418px;" />
11 * Input: points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]
12 * Output: [3,2,2]
13 * Explanation: The points and circles are shown above.
14 * queries[0] is the green circle, queries[1] is the red circle, and queries[2] is the blue circle.
15 * 
16 * Example 2:
17 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/25/chrome_2021-03-25_22-42-07.png" style="width: 500px; height: 390px;" />
18 * 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]]
19 * Output: [2,3,2,4]
20 * Explanation: The points and circles are shown above.
21 * queries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is purple.
22 * 
23 *  
24 * Constraints:
25 * 
26 * 	1 <= points.length <= 500
27 * 	points[i].length == 2
28 * 	0 <= x​​​​​​i, y​​​​​​i <= 500
29 * 	1 <= queries.length <= 500
30 * 	queries[j].length == 3
31 * 	0 <= xj, yj <= 500
32 * 	1 <= rj <= 500
33 * 	All coordinates are integers.
34 * 
35 *  
36 * Follow up: Could you find the answer for each query in better complexity than O(n)?
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/
42// discuss: https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn count_points(points: Vec<Vec<i32>>, queries: Vec<Vec<i32>>) -> Vec<i32> {
48        vec![]
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_1828() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.