The Queries on Number of Points Inside a Circle problem gives you a list of 2D points and a list of circle queries (center, radius). For each query, count how many points lie inside or on the circle boundary. This easy-to-medium coding problem tests basic geometric distance comparison. The array, math, and geometry interview pattern is demonstrated.
Google asks this to test geometric intuition — specifically using the squared distance formula to avoid floating-point square roots. For small inputs, O(n × q) brute force is acceptable.
Brute force with squared distance. For each query (cx, cy, r): count points (px, py) where (px-cx)² + (py-cy)² ≤ r². Using squared distance avoids sqrt computation, keeping comparisons exact integer arithmetic.
points=[(1,3),(3,3),(5,3),(2,2)], queries=[(2,3,1),(4,3,1),(1,1,2)].
sqrt((px-cx)² + (py-cy)²) ≤ r with float precision issues.≤ (points on boundary are included).Geometric distance problems almost always use squared distance to avoid floating-point issues. The condition dx² + dy² ≤ r² is exact for integer coordinates. For large inputs with many queries, consider spatial indexing (k-d tree, grid bucketing). Practice this pattern: "count points in rectangle," "count points in polygon" — all use the same squared-distance comparison principle.