1
class Solution:
2
def strongPasswordChecker(self, password: str) -> int:
3
# vimla_kushwaha
4
s = password
5
missing_type = 3
6
if any("a" <= c <= "z" for c in s):
7
missing_type -= 1
8
if any("A" <= c <= "Z" for c in s):
9
missing_type -= 1
10
if any(c.isdigit() for c in s):
11
missing_type -= 1
12

13
change = 0
14
one = two = 0
15
p = 2
16
while p < len(s):
17
if s[p] == s[p - 1] == s[p - 2]:
18
length = 2
19
while p < len(s) and s[p] == s[p - 1]:
20
length += 1
21
p += 1
22

23
change += length // 3
24
if length % 3 == 0:
25
one += 1
26
elif length % 3 == 1:
27
two += 1
28
else:
29
p += 1
30

31
if len(s) < 6:
32
return max(missing_type, 6 - len(s))
33
elif len(s) <= 20:
34
return max(missing_type, change)
35
else:
36
delete = len(s) - 20
37

38
change -= min(delete, one)
39
change -= min(max(delete - one, 0), two * 2) // 2
40
change -= max(delete - one - 2 * two, 0) // 3
41

42
return int(delete + max(missing_type, change))

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0