classSolution {
private:int maxConsecutiveAnswersWith(string keys, int k, char c) {
int left =0, right =0, res =0, n = keys.size();
int cnt =0;
while (right < n) {
char key = keys[right++];
while (key == c && cnt == k) {
if (keys[left++] == c) {
cnt--;
}
}
if (key == c) cnt++;
res = max(res, right-left);
}
return res;
}
public:int maxConsecutiveAnswers(string answerKey, int k) {
returnmax(maxConsecutiveAnswersWith(answerKey, k, 'T'),
maxConsecutiveAnswersWith(answerKey, k, 'F'));
}
};