Maximize the Confusion of an Exam LeetCode solution in Python

1
# Runtime: 482 ms (Top 77.29%) | Memory: 14.4 MB (Top 36.09%)
2
class Solution:
3
def maxConsecutiveAnswers(self, string: str, k: int) -> int:
4
result = 0
5
j = 0
6
count1 = k
7
for i in range(len(string)):
8
if count1 == 0 and string[i] == "F":
9
while string[j] != "F":
10
j += 1
11
count1 += 1
12
j += 1
13

14
if string[i] == "F":
15
if count1 > 0:
16
count1 -= 1
17

18
if i - j + 1 > result:
19
result = i - j + 1
20

21
j = 0
22
count2 = k
23
for i in range(len(string)):
24
if count2 == 0 and string[i] == "T":
25
while string[j] != "T":
26
j += 1
27
count2 += 1
28
j += 1
29

30
if string[i] == "T":
31
if count2 > 0:
32
count2 -= 1
33

34
if i - j + 1 > result:
35
result = i - j + 1
36

37
return result

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0