2249. Count Lattice Points Inside a Circle LeetCode Solution
In this guide, you will get 2249. Count Lattice Points Inside a Circle LeetCode Solution with the best time and space complexity. The solution to Count Lattice Points Inside a Circle problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Count Lattice Points Inside a Circle solution in C++
- Count Lattice Points Inside a Circle solution in Java
- Count Lattice Points Inside a Circle solution in Python
- Additional Resources

Problem Statement of Count Lattice Points Inside a Circle
Given a 2D integer array circles where circles[i] = [xi, yi, ri] represents the center (xi, yi) and radius ri of the ith circle drawn on a grid, return the number of lattice points that are present inside at least one circle.
Note:
A lattice point is a point with integer coordinates.
Points that lie on the circumference of a circle are also considered to be inside it.
Example 1:
Input: circles = [[2,2,1]]
Output: 5
Explanation:
The figure above shows the given circle.
The lattice points present inside the circle are (1, 2), (2, 1), (2, 2), (2, 3), and (3, 2) and are shown in green.
Other points such as (1, 1) and (1, 3), which are shown in red, are not considered inside the circle.
Hence, the number of lattice points present inside at least one circle is 5.
Example 2:
Input: circles = [[2,2,2],[3,4,1]]
Output: 16
Explanation:
The figure above shows the given circles.
There are exactly 16 lattice points which are present inside at least one circle.
Some of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4).
Constraints:
1 <= circles.length <= 200
circles[i].length == 3
1 <= xi, yi <= 100
1 <= ri <= min(xi, yi)
Complexity Analysis
- Time Complexity: O(200^2n) = O(n)
- Space Complexity: O(1)
2249. Count Lattice Points Inside a Circle LeetCode Solution in C++
class Solution {
public:
int countLatticePoints(vector<vector<int>>& circles) {
int ans = 0;
for (int x = 0; x < 201; ++x)
for (int y = 0; y < 201; ++y)
ans += ranges::any_of(circles, [x, y](const auto& c) {
return (c[0] - x) * (c[0] - x) + (c[1] - y) * (c[1] - y) <=
c[2] * c[2];
});
return ans;
}
};
/* code provided by PROGIEZ */
2249. Count Lattice Points Inside a Circle LeetCode Solution in Java
class Solution {
public int countLatticePoints(int[][] circles) {
int ans = 0;
for (int x = 0; x < 201; ++x)
for (int y = 0; y < 201; ++y)
for (int[] c : circles)
if ((c[0] - x) * (c[0] - x) + (c[1] - y) * (c[1] - y) <= c[2] * c[2]) {
++ans;
break;
}
return ans;
}
}
// code provided by PROGIEZ
2249. Count Lattice Points Inside a Circle LeetCode Solution in Python
class Solution:
def countLatticePoints(self, circles: list[list[int]]) -> int:
return sum(any((xc - x)**2 + (yc - y)**2 <= r**2 for xc, yc, r in circles)
for x in range(201)
for y in range(201))
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.