File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 1
1
# @link Problem definition
2
2
# [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/ctci-ransom-note.md]]
3
3
4
- from typing import Dict
4
+ from typing import Dict , List
5
5
6
6
__YES__ = 'Yes'
7
7
__NO__ = 'No'
8
8
9
9
10
- def check_magazine_compute (magazine : str , note : str ) -> bool :
10
+ def check_magazine_compute (magazine : List [ str ] , note : List [ str ] ) -> bool :
11
11
dictionary : Dict [str , int ] = {}
12
12
13
- for x in magazine :
13
+ word : str
14
14
15
- if x in dictionary :
16
- dictionary [x ] += 1
15
+ for word in magazine :
16
+
17
+ if word in dictionary :
18
+ dictionary [word ] += 1
17
19
else :
18
- dictionary [x ] = 1
20
+ dictionary [word ] = 1
19
21
20
- for x in note :
22
+ for word in note :
21
23
22
- if x in dictionary and dictionary [x ] > 0 :
23
- dictionary [x ] -= 1
24
+ if word in dictionary and dictionary [word ] > 0 :
25
+ dictionary [word ] -= 1
24
26
else :
25
27
return False
26
28
27
29
return True
28
30
29
31
30
- def check_magazine (magazine : str , note : str ) -> str :
32
+ def check_magazine (magazine : List [ str ] , note : List [ str ] ) -> str :
31
33
return __YES__ if check_magazine_compute (magazine , note ) else __NO__
You can’t perform that action at this time.
0 commit comments