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 i^th 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
Inputcircles = [[2,2,1]]
Output5
The lattice points inside the circle are (1, 2), (2, 1), (2, 2), (2, 3), and (3, 2), so the answer is 5.
Example 2
Inputcircles = [[2,2,2],[3,4,1]]
Output16
There are exactly 16 lattice points that are present inside at least one of the given circles.

Constraints

  • 1 <= circles.length <= 200
  • circles[i].length == 3
  • 1 <= xi, yi <= 100
  • 1 <= ri <= min(xi, yi)

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate