FastPrepSimpleRDD Multiset Intersection

SimpleRDD Multiset Intersection

DatologyAI logoDatologyAI● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Return the multiset intersection of two integer collections. A value appears in the result as many times as the minimum of its frequencies in the two inputs.

Preserve the order of qualifying occurrences from left.

Function

simpleRddIntersection(left: int[], right: int[]) → int[]

Examples

Example 1

left = [1,3,3]right = [3,4,3]return = [3,3]

The value 3 occurs twice in both inputs.

Example 2

left = [4,9,5,9]right = [9,4,9,8]return = [4,9,9]

Qualifying occurrences retain their order from the left input.

Example 3

left = []right = [1,2]return = []

An empty input has an empty intersection.

Constraints

  • 0 <= left.length, right.length <= 200000.
  • Each value fits in a signed 32-bit integer.

More DatologyAI problems

See DatologyAI hiring insights
public int[] simpleRddIntersection(int[] left, int[] right) {
    // Write your solution here.
}
left[1,3,3]
right[3,4,3]
expected[3,3]
Checking account…