-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathransom_note.py
More file actions
60 lines (40 loc) · 1.22 KB
/
ransom_note.py
File metadata and controls
60 lines (40 loc) · 1.22 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
https://www.hackerrank.com/challenges/ctci-ransom-note/problem
#!/bin/python3
import math
import os
import random
import re
import sys
def createNote(note):
# note=note.split(' ')
noteDict={}
for word in note:
noteDict[word]=noteDict.get(word,0)+1
return noteDict
# Complete the checkMagazine function below.
def checkMagazine(magazine, note):
#magazine and note are strings.
#Create a list of magazine.done
#Create a dict of note.key is the word. value is the frequency.done
#Iterate through the magazine list. If note empty then #return true. If magazine list empty and note not empty; #Return false.O(magazine)
# magazine=magazine.split(' ')
note=createNote(note)
for x in magazine:
if x in note.keys():
if note[x]>0:
note[x]=note.get(x)-1
elif note[x]<1:
note.pop(x)
for x in note:
if note[x]!=0:
print("No")
return
print("Yes")
return
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)