2024. Maximize the Confusion of an Exam
Either make T to F or F to T
class Solution:
def maxConsecutiveAnswers(self, answerKey: str, k: int) -> int:
n = len(answerKey)
#T F
k1, k2 = k, k
l1, l2 = 0, 0
c1, c2 = 0, 0
res = 0
for i in range(n):
if answerKey[i] == "F":
k1 -= 1
if k1 < 0:
while l1 < n and answerKey[l1] == 'T':
l1 += 1
l1 += 1
k1 += 1
else:
k2 -= 1
if k2 < 0:
while l2 < n and answerKey[l2] == 'F':
l2 += 1
l2 += 1
k2 += 1
c1 = max(c1, (i - l1 + 1))
c2 = max(c2, (i - l2 + 1))
res = max(res, c1, c2)
return res