-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
34 lines (26 loc) · 757 Bytes
/
solution.py
File metadata and controls
34 lines (26 loc) · 757 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
def Small (S):
if len(S) <= 1:
return len(S)
unique_characters = sorted(list(set(S)))
minimum = len(S)
start = 0
end = 0
val_dict = {}
while end < len(S):
if S[end] not in val_dict:
val_dict[S[end]] = 1
else:
val_dict[S[end]] += 1
while unique_characters == sorted(val_dict.keys()):
current = end - start + 1
if current < minimum:
minimum = current
val_dict[S[start]] -= 1
if val_dict[S[start]] == 0:
del val_dict[S[start]]
start += 1
end += 1
return minimum
S = input()
out_ = Small(S)
print (out_)