반응형

https://leetcode.com/problems/maximize-the-confusion-of-an-exam/description/

 

Maximize the Confusion of an Exam - LeetCode

Can you solve this real interview question? 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

leetcode.com

 

 

class Solution {
public:
    int count(string& a, int k, char c) {
        int j = 0, cnt = 0;
        for(int i = 0; i<a.size(); i++) {
            cnt += a[i] == c;
            if(cnt > k) cnt -= a[j++] == c; 
        }
        return a.size() - j;
    }

    int maxConsecutiveAnswers(string answerKey, int k) {
        return max(
            count(answerKey, k, 'T'), count(answerKey, k, 'F')
        );
    }
};
반응형

+ Recent posts