File tree 1 file changed +47
-0
lines changed
1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/bin/python3
2
+
3
+ import math
4
+ import os
5
+ import random
6
+ import re
7
+ import sys
8
+
9
+ # Complete the isValid function below.
10
+ def isValid (s ):
11
+
12
+ freqCounts = [s .count (char ) for char in set (s ) ]
13
+ print (freqCounts )
14
+
15
+ if max (freqCounts ) - min (freqCounts ) == 0 : #all frequencies are same
16
+ return 'YES'
17
+
18
+ #If difference between highest count and lowest count is 1
19
+ #and there is only one letter with highest count,
20
+ #then return 'YES' (because we can subtract one of these
21
+ #letters and max=min , i.e. all counts are the same)
22
+
23
+ elif freqCounts .count (max (freqCounts )) == 1 and max (freqCounts ) - min (freqCounts ) == 1 :
24
+ return 'YES'
25
+
26
+ #If the minimum count is 1
27
+ #remove this character, and check whether all the other counts are the same
28
+
29
+ elif freqCounts .count (min (freqCounts )) == 1 :
30
+ freqCounts .remove (min (freqCounts ))
31
+ if max (freqCounts )- min (freqCounts ) == 0 :
32
+ return 'YES'
33
+ else :
34
+ return 'NO'
35
+ else :
36
+ return 'NO'
37
+
38
+ if __name__ == '__main__' :
39
+ fptr = open (os .environ ['OUTPUT_PATH' ], 'w' )
40
+
41
+ s = input ()
42
+
43
+ result = isValid (s )
44
+
45
+ fptr .write (result + '\n ' )
46
+
47
+ fptr .close ()
You can’t perform that action at this time.
0 commit comments