-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashTablesRansomNote.py
More file actions
40 lines (29 loc) · 838 Bytes
/
Copy pathHashTablesRansomNote.py
File metadata and controls
40 lines (29 loc) · 838 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
31
32
33
34
35
36
37
38
39
40
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the checkMagazine function below.
def checkMagazine(magazine, note):
words_dict = {word: 0 for word in note}
for word in note:
words_dict[word] += 1
words_pending = len(note)
i = 0
while words_pending > 0 and i < len(magazine):
if magazine[i] in words_dict:
if words_dict[magazine[i]] > 0:
words_dict[magazine[i]] -= 1
words_pending -= 1
else:
words_dict.pop(magazine[i])
i += 1
print('Yes' if words_pending <= 0 else 'No')
if __name__ == '__main__':
mn = input().split()
m = int(mn[0])
n = int(mn[1])
magazine = input().rstrip().split()
note = input().rstrip().split()
checkMagazine(magazine, note)