We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Greedy
- Beautiful Pairs
- Discussions
Beautiful Pairs
Beautiful Pairs
Sort by
recency
|
279 Discussions
|
Please Login in order to post a comment
Ruby
case 5 1 1 1 output 0 how is that
case 5 1 1 1 output 0 how is that
python
from collections import Counter def beautifulPairs(A, B): a=Counter(A) b=Counter(B) pairs=0 for i in a: if i in b: pairs+=min(a[i],b[i]) if pairs==len(A): return pairs-1 else: return pairs+1