Problem Description
You are given a list of points in a 2D plane and an array of queries where each query describes a circle (with a center point and a radius). For each query, count how many points fall inside or on the boundary of the circle.
Key Insights
- Use the distance formula (squared) to compare the distance between a point and the query center without using square roots.
- Check if (point_x - query_x)² + (point_y - query_y)² is less than or equal to radius².
- The constraints (with points and queries up to 500 each) allow a simple O(n * m) solution.
- For the follow-up aiming for better than O(n) per query, consider spatial indexing (such as a k-d tree or sorting followed by binary search), though the naive solution is acceptable given the constraint sizes.
Space and Time Complexity
Time Complexity: O(n * m) where n is the number of points and m is the number of queries. Space Complexity: O(1) extra space (ignoring input and output data storage).
Solution
For each query, iterate over all points and calculate the squared distance between the point and the center of the circle. If this squared distance is less than or equal to the squared radius, the point is inside the circle (or on its boundary). Increment the count for that query accordingly and return the results for all queries.