-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathransom.py
More file actions
30 lines (26 loc) · 698 Bytes
/
ransom.py
File metadata and controls
30 lines (26 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def ransom_note(magazine, ransom):
"""
Finds out if it is possible to create ransom with subset of magazine
"""
if len(magazine) < len(ransom):
return False
mwords = {}
for word in magazine:
if word in mwords:
mwords[word] += 1
else:
mwords[word] = 1
for word in ransom:
if not (word in mwords) or mwords[word] == 0:
return False
else:
mwords[word] -= 1
return True
m, n = map(int, input().strip().split(' '))
magazine = input().strip().split(' ')
ransom = input().strip().split(' ')
answer = ransom_note(magazine, ransom)
if(answer):
print("Yes")
else:
print("No")