Skip to content

Instantly share code, notes, and snippets.

@tuantm8
Created June 13, 2017 07:55
Show Gist options
  • Select an option

  • Save tuantm8/4f92abc5c062321dd4771cd6123c4f29 to your computer and use it in GitHub Desktop.

Select an option

Save tuantm8/4f92abc5c062321dd4771cd6123c4f29 to your computer and use it in GitHub Desktop.
Hackerrank Crack the coding interview Ransom note
def ransom_note(magazine, ransom):
if len(magazine) < len(ransom):
return False
dict_magazine = dict()
dict_ransom = dict()
for word in magazine:
if word not in dict_magazine:
dict_magazine[word] = 1
else:
dict_magazine[word] += 1
for word in ransom:
if (word not in dict_magazine) or (dict_magazine[word] == 0):
return False
else:
dict_magazine[word] -= 1
return True
m, n = map(int, raw_input().strip().split(' '))
magazine = raw_input().strip().split(' ')
ransom = raw_input().strip().split(' ')
answer = ransom_note(magazine, ransom)
if(answer):
print "Yes"
else:
print "No"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment