Count Distinct Tags in a Fixed-Radius Circle (Practice Reconstruction)
Problem statement
The inputs describe points with tags. Point i has tag S[i] and integer coordinates (X[i], Y[i]).
For this exercise, assume the circle is centred at (0,0), has the supplied fixed radius R, and includes its boundary. Records may share coordinates.
Count the different tags among points inside or on the circle. Count a tag only once, even if several points have that tag. Use the given radius; do not choose a different one.
Function
solution(S: String, X: int[], Y: int[], R: int) → intExamples
Example 1
S = "ABAC"X = [1,2,-1,4]Y = [0,0,0,0]R = 2return = 2This authored example encloses both A points and the B point. Their distinct tags are A and B; C lies outside.
Example 2
S = "AB"X = [3,3]Y = [4,5]R = 5return = 1This authored example includes A exactly on the radius-five boundary. B is farther away and is excluded.
Example 3
S = "AAB"X = [0,0,0]Y = [0,0,0]R = 0return = 2This authored example has a zero-radius circle and three records at its centre. Tags A and B contribute two distinct values.
Constraints
- For this exercise, assume
0 <= S.length = X.length = Y.length <= 100000. - For this exercise, assume tags are uppercase English letters.
- For this exercise, assume
-10^9 <= X[i], Y[i] <= 10^9and0 <= R <= 10^9.