FastPrepCount Distinct Tags in a Fixed-Radius Circle (Practice Reconstruction)

Count Distinct Tags in a Fixed-Radius Circle (Practice Reconstruction)

Marshall Wace logoMarshall Wace● EasyFULLTIMEOA

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) → int

Examples

Example 1

S = "ABAC"X = [1,2,-1,4]Y = [0,0,0,0]R = 2return = 2

This 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 = 1

This 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 = 2

This 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^9 and 0 <= R <= 10^9.

More Marshall Wace problems

See Marshall Wace hiring insights
Saved
public int solution(String S, int[] X, int[] Y, int R) {
    // Write your solution here.
}
S"ABAC"
X[1,2,-1,4]
Y[0,0,0,0]
R2
expected2
Checking account…