-
Notifications
You must be signed in to change notification settings - Fork 108
/
solution.py
39 lines (28 loc) · 785 Bytes
/
solution.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/python3
import math
import os
import random
import re
import sys
import collections
# Complete the isValid function below.
def isValid(s):
#variable which stores all letters with their frequencies
counter=collections.Counter(s);
value,difference=0,0
#loop to check if the value(s) that is/are different differ only by 1
for cnt in counter.values():
if value==0:
value=cnt
if value!=cnt:
difference+=1 #if difference more than 1 then the string cannot become valid
if difference<=1:
return "YES"
else:
return "NO"
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
result = isValid(s)
fptr.write(result + '\n')
fptr.close()