Created
June 13, 2017 07:55
-
-
Save tuantm8/4f92abc5c062321dd4771cd6123c4f29 to your computer and use it in GitHub Desktop.
Hackerrank Crack the coding interview Ransom note
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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