Count Lattice Points Inside a Circle - Brute Force & Euclidean Distance [JS]
Description Solution: Brute Force & Euclidean Distance Get the maximum x and y coordinate on the grid (remember to consider the points within the radius) Loop through each point in the grid Loop through each circle and check whether the distance between the circle center and grid point <= radius. Calculate the distance using the euclidean distance algorithm. n = number of circles, m = number of points on the grid Time Complexity: O(nm) Space Complexity: O(1) var countLatticePoints = function ( circles ) { let points = 0 ; let maxX = 0 , maxY = 0 ; for ( let [x, y, r] of circles) { maxX = Math .max(maxX, x + r); // x + r: consider points within the radius maxY = Math .max(maxY, y + r); // x + y: consider points within the radius } for ( let i = 0 ; i <= maxX; i++) { for ( let j = 0 ; j <= maxY; j++) { for ( let [x, y, r] of circles) { if (getDist([i, j], [x, y]) <= r) { poi...