-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathSherlockValidString.py
More file actions
39 lines (32 loc) · 879 Bytes
/
SherlockValidString.py
File metadata and controls
39 lines (32 loc) · 879 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
#!/bin/python3
import os
# Complete the isValid function below.
def isValid(s):
scount=[0 for i in range(26)]
ret='YES'#return value
for i in s: scount[ord(i)-97]+=1
aux=[i for i in scount if i!=0]
d={}
max_value=0
for i in aux:
d[i]=d.get(i,0)+1
if d[i]>max_value:
max_key,max_value=i,d[i]#most frequent
diff_elem_count=0
for i in d:
if i!=max_key:
if i==max_key+1 or i==1:
diff_elem_count+=d[i]
if diff_elem_count>1:
ret='NO'
break
else:
ret='NO'
break
return ret
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
result = isValid(s)
fptr.write(result + '\n')
fptr.close()