FastPrepMultiset Intersection of Three Lists

Multiset Intersection of Three Lists

ZipRecruiter logoZipRecruiter● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

You are given three integer arrays, first, second, and third.

Return their multiset intersection in ascending order. Each value must appear exactly the minimum of its frequencies across the three arrays. Every input occurrence may be used at most once.

Function

multisetIntersection(first: int[], second: int[], third: int[]) → int[]

Examples

Example 1

first = [2,2,3,4,5]second = [2,2,2,3]third = [1,2,2,3,3]return = [2,2,3]

Value 2 occurs at least twice in every array, while value 3 occurs at least once.

Example 2

first = [1,1,2]second = [1,2,2]third = [1,1,1,2]return = [1,2]

The minimum frequency of each of 1 and 2 is one.

Constraints

  • 0 <= first.length,second.length,third.length <= 100000
  • -1000000000 <= value <= 1000000000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int[] multisetIntersection(int[] first, int[] second, int[] third) {
    // Write your code here.
}
first[2,2,3,4,5]
second[2,2,2,3]
third[1,2,2,3,3]
expected[2,2,3]
Checking account…