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.
This solution is not correct. The subtraction "-" operator does not work with way on Counter objects (invert magazine and ransom to see this). Instead, use the .subtract like so:
from collections import Counter
def ransom_note(magazine, ransom):
m, r = Counter(magazine), Counter(ransom)
m.subtract(r)
return (min(m.viewvalues()) >= 0)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
This solution is not correct. The subtraction "-" operator does not work with way on Counter objects (invert magazine and ransom to see this). Instead, use the .subtract like so:
from collections import Counter
def ransom_note(magazine, ransom):