Skip to content

Instantly share code, notes, and snippets.

@ray1422
Created September 18, 2019 12:52
Show Gist options
  • Save ray1422/203a9c9a8b7fbec209bd3404c4d4aa7b to your computer and use it in GitHub Desktop.
Save ray1422/203a9c9a8b7fbec209bd3404c4d4aa7b to your computer and use it in GitHub Desktop.
k = int(input())
my_str = input()
canvas = [0] * len(my_str)
# step one: mark all the "switch point"
# for a example, aAbBcCdD, mark the 'a' of aA, 'A' of Ab
for i in range(len(my_str) - 1):
if (my_str[i].islower() and my_str[i + 1].isupper()) or (my_str[i].isupper() and my_str[i + 1].islower()):
canvas[i] = 1
# 1000010010010010000000
# AAAAAAbbbCCCdddEEEEEEE
# step 2: find the gaps that as long as K
my_str2 = ''
for i in range(len(my_str)):
my_str2 += '_' if canvas[i] == 0 else '_ '
my_str2_arr = my_str2.split()
length = 0
max_length = 0
is_starter = True
for arr in my_str2_arr:
if len(arr) == k:
length += 1
max_length = max(length, max_length)
is_starter = False
elif is_starter:
if len(arr) >= k:
length += 1
is_starter = False
max_length = max(length, max_length)
else:
if len(arr) >= k:
length += 1
max_length = max(length, max_length)
length = 1
is_starter = False
else:
max_length = max(length, max_length)
length = 0
is_starter = True
print(max_length * k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment