Maximize the Confusion of an Exam LeetCode solution in C++
1class Solution {2public:3int maxConsecutiveAnswers(string answerKey, int k) {4return max(helper(answerKey, k, 'T'), helper(answerKey, k, 'F'));5}67int helper(string answerKey, int k, char c) {8int start = 0;9int end = 0;10int count = 0;11int ans = 0;12while (end < answerKey.length()) {13if (answerKey[end] == c) count++;14while (count > k) {15if (answerKey[start] == c) count--;16start++;17}18ans = max(ans, end - start + 1);19end++;20}21return ans;22}23};