You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane. Multiple points can have the same coordinates.
3
+
4
+
You are also given an array queries where queries[j] = [xj, yj, rj] describes a circle centered at (xj, yj) with a radius of rj.
5
+
6
+
For each query queries[j], compute the number of points inside the jth circle. Points on the border of the circle are considered inside.
7
+
8
+
Return an array answer, where answer[j] is the answer to the jth query.
9
+
10
+
Constraints:
11
+
12
+
1 <= points.length <= 500
13
+
points[i].length == 2
14
+
0 <= x??????i, y??????i <= 500
15
+
1 <= queries.length <= 500
16
+
queries[j].length == 3
17
+
0 <= xj, yj <= 500
18
+
1 <= rj <= 500
19
+
All coordinates are integers.
20
+
21
+
*/
22
+
classPointInsideCircle {
23
+
doubleequation(intarr[], intbrr[]) //function taht take points and circle constants as input and return Decimal values.
24
+
{
25
+
returnMath.pow((brr[0]-arr[0]),2) + Math.pow((brr[1]-arr[1]),2) - Math.pow(arr[2],2); //returning value after putting the points on circle
26
+
}
27
+
publicint[] countPoints(int[][] points, int[][] queries) { //Given function
28
+
intres[] = newint[queries.length]; //Array res of type integer
29
+
for(inti = 0; i<queries.length; i++) //for loop that itrates over queries (circle)
30
+
{
31
+
intcount = 0; //count variable of type int
32
+
for(intj = 0; j<points.length; j++) //for loop that itrates over all given points
33
+
{
34
+
if(equation(queries[i],points[j]) <= 0) //checking that the value is less than or 0 after putting the value in eqation
35
+
count++; //incrementing the value of count
36
+
}
37
+
res[i] = count; //storing the value of count in res Array
0 commit comments