2024. Maximize the Confusion of an Exam
Medium
A teacher is writing a test with n
true/false questions, with 'T'
denoting true and 'F'
denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple trues or multiple falses in a row).
You are given a string answerKey
, where answerKey[i]
is the original answer to the ith
question. In addition, you are given an integer k
, the maximum number of times you may perform the following operation:
Change the answer key for any question to
'T'
or'F'
(i.e., setanswerKey[i]
to'T'
or'F'
).
Return the maximum number of consecutive 'T'
s or 'F'
s in the answer key after performing the operation at most k
times.
Example 1:
Example 2:
Example 3:
Constraints:
n == answerKey.length
1 <= n <= 5 * 10^4
answerKey[i]
is either'T'
or'F'
1 <= k <= n
解題
其實就是 1004 題做兩遍取大值。
雖然可以一次做完,但是程式碼會比較難讀。
Last updated