Created
March 22, 2022 12:33
-
-
Save prrraveen/d0e9cb9c859452f22dbe4e9d0a343a9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(S): | |
# print(F"S = {S}") | |
def is_valid(x): | |
if x.isdigit(): | |
if len(x) % 2 == 1: | |
return True | |
# elif x in range(ord('A'), ord('Z') + 1) or x in range(ord('a'), ord('z') + 1): | |
elif x.isalpha(): | |
if len(x) % 2 == 0: | |
return True | |
elif x.isalnum(): | |
digit_count = letter_count = 0 | |
for ch in x: | |
if ch.isalpha(): | |
letter_count += 1 | |
else: | |
digit_count += 1 | |
if digit_count % 2 == 1 and letter_count % 2 == 0: | |
return True | |
return False | |
S = S.split(' ') | |
# print(F"S = {S}") | |
S.sort(key=lambda x: len(x)) | |
# print(F"S = {S}") | |
S = S[::-1] | |
# print(F"S = {S}") | |
for password in S: | |
if is_valid(password): | |
return len(password) | |
return -1 | |
s = "test 5 a0A pass007 ?xy1" | |
s = "?xy1" | |
s = '5' | |
s = '55' #-1 | |
s = 'A' # -1 | |
s = 'AA' | |
s = 'AAaa112 ' | |
s = 'asdf! 3ab qqqq adw3' | |
print(F"solution(s) = {solution(s)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment