Multiset overlap (source code)

= Multiset overlap
{title2=$|A\cap B|=\sum_x\min(m_A(x),m_B(x))$}

The common multiplicity of two <multisets>, summing the smaller multiplicity of each value. To return an order-preserving overlap of two finite <lists>, scan the first list and consume one equal item from the second whenever available. Each token can be consumed at most once, so the resulting <subsequence> has maximum possible length among those that occur in a permutation of the second list.