Created
June 4, 2017 15:30
-
-
Save tasdikrahman/26278febf461999467272f950022d193 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Requirements: | |
# - upper case characters >= 1 | |
# - no digits | |
# I/p | |
# S -> len(S) = N | |
# O/P -> len(longest_substring) which passes requirements | |
import re | |
from string import ascii_uppercase | |
def check_caps(sub_string): | |
caps_strings = [] | |
for i in sub_string: | |
if any(x in ascii_uppercase for x in i) == True: | |
caps_strings.append(i) | |
return caps_strings | |
def get_sub_strings(S): | |
return re.compile("\d").split(S) | |
def solution(S): | |
sub_strings = get_sub_strings(S) | |
caps_strings = check_caps(sub_strings) | |
if len(caps_strings) == 0: | |
return -1 | |
else: | |
longest_string = max(caps_strings, key=len) | |
return len(longest_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment