Reported February 2022
ZipRecruiterhash table

Multiset Intersection of Three Lists

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

The ZipRecruiter OA reported in February 2022 looks like a throwaway: intersect three arrays. Then you hit the duplicates rule and a naive set intersection returns [2,3] instead of [2,2,3]. Each value has to show up min-frequency times across all three lists, sorted ascending. It's a counting problem dressed up as a set problem, and the edge cases (empty arrays, negatives up to a billion in magnitude) are where people lose points. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and can hand you the approach while the proctor sees nothing.

The problem

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

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is frequency counting. Build a hash map of counts for each array, then walk the keys of one map and take the minimum count across all three. Emit that value that many times, then sort the result. Or sort all three arrays and run three pointers, advancing the smallest, which gives sorted output for free and needs no extra memory. The common pitfall is using sets, which collapse duplicates and give the wrong answer on Example 1. Another one is forgetting that any empty array makes the whole result empty. Don't sort with a string comparator either, since values go negative. With 100000 elements per array, O(n log n) or O(n) is fine. If the live OA rattles you, StealthCoder is the hedge that reads the prompt and gives you a working solution on screen.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Multiset Intersection of Three Lists cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass ZipRecruiter's OA.

ZipRecruiter reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Multiset Intersection of Three Lists FAQ

What's the trick in the ZipRecruiter multiset intersection problem?+

Count frequencies, don't use sets. A set drops duplicates, so [2,2,3] becomes [2,3] and fails. For each value, take the minimum count across all three arrays and output the value that many times, in ascending order.

Hash map or three pointers, which is better?+

Both work at this size. Three pointers on sorted arrays gives sorted output directly and uses little extra space. Hash maps are easier to write under pressure, but you must sort the final result or iterate keys in sorted order.

What edge cases should I test?+

Test any empty array, which forces an empty result. Test values that appear in only two of the three arrays. Test negative numbers and values near 1,000,000,000. Also test a value with very different counts, like 1 in one array and 5 in another.

How hard is this really?+

Easy to medium. The logic is short, but the duplicate rule catches people who reach for set intersection. If you know the counting approach, it's a ten minute problem. The risk is rushing and missing the minimum-frequency rule.

How do I prepare in 48 hours?+

Write the counting solution and the three-pointer solution once each. Then practice the variants: two arrays, k arrays, and intersection with a limit on use per element. Run Example 1 and 2 by hand before you submit anything.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it