2024. Maximize the Confusion of an Exam
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:
'T'
or 'F'
(i.e., set answerKey[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
n
<= 5 * 104answerKey[i]
is either 'T'
or 'F'
k
<= n
Ron ChenFri, Jul 7, 2023
做了一週sliding window,終於一次過了,思路跟前天的1493題一樣,只是這次T跟F都要各數一次。
MarsgoatFri, Jul 7, 2023
JimJul 8, 2023