Quant Memo
Coding/●●●●●

Intersection of two watchlists

Two analysts each hand you a watchlist (a list of symbols that may contain repeats). Return the symbols the two lists have in common, where a symbol appears in the result as many times as it appears in both lists, that is, the minimum of its two counts.

a = ["A", "A", "B"], b = ["A", "B", "B"]
-> ["A", "B"]      # A: min(2,1)=1, B: min(1,2)=1

Return the multiset intersection. Aim for O(m+n)O(m + n).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions