Maximize the Confusion of an Exam
Description
Students answer True/False questions. You can change at most k answers. Maximize the length of consecutive same answers. Return the result as an integer.
Examples
answerKey = "TTFF", k = 24Change 2 F's to T's.
answerKey = "TFTFTF", k = 36Change either 3 F's to T's (getting "TTTTTT" but only using 3 changes gives us "TTTFTF" with 3 consecutive T's, or "TFTFTT" with 2 consecutive T's) or 2 T's to F's (getting "FFFFFF" but only using 2 changes gives us 5 consecutive same answers). The optimal is changing 2 T's at positions 0 and 2 to get "FFFFF" for the first 5 positions.
answerKey = "FFFFFFFF", k = 08When k=0, it is not possible to make any changes, so the task requires find the longest existing sequence of consecutive same answers. Since all answers are already 'F', the maximum consecutive length is the entire string length of 8.
Constraints
- •
1 ≤ answerKey.length ≤ 5 × 10⁴
Ready to solve this problem?
Practice solo and sharpen your skills for technical interviews.