-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsticker.py
executable file
·40 lines (31 loc) · 1.02 KB
/
sticker.py
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
#!/bin/env python3.5
'''
Given stickers labeled "linkedin", identify the number of stickers required to build
a specific string from its individual characters.
eg: input: link, output: 1
input: lined in output: 1
input: kindled output: 2
input: kite output: 0
'''
import sys
sticker = 'linkedin'
string = input()
sticker_count = dict.fromkeys(set(sticker),0)
for i in sticker:
sticker_count[i] = sticker_count[i] + 1
string_count = dict.fromkeys(set(string),0)
for i in string:
string_count[i] = string_count[i] + 1
mod_dict = sticker_count.copy()
count = 1
for i in string_count.keys():
max = count
if i not in sticker_count.keys():
print("Found a character not in sticker string")
sys.exit(1)
while mod_dict[i] < string_count[i]:
count = count + 1
mod_dict = {i:mod_dict[i]+sticker_count[i] for i in sticker_count.keys()}
if count > max:
max = count
print("Stickers required is %d" %max)