Maximize the Confusion of an Exam LeetCode solution in Python
1# Runtime: 482 ms (Top 77.29%) | Memory: 14.4 MB (Top 36.09%)2class Solution:3def maxConsecutiveAnswers(self, string: str, k: int) -> int:4result = 05j = 06count1 = k7for i in range(len(string)):8if count1 == 0 and string[i] == "F":9while string[j] != "F":10j += 111count1 += 112j += 11314if string[i] == "F":15if count1 > 0:16count1 -= 11718if i - j + 1 > result:19result = i - j + 12021j = 022count2 = k23for i in range(len(string)):24if count2 == 0 and string[i] == "T":25while string[j] != "T":26j += 127count2 += 128j += 12930if string[i] == "T":31if count2 > 0:32count2 -= 13334if i - j + 1 > result:35result = i - j + 13637return result