Maximize the Confusion of an Exam LeetCode solution in C++

1
class Solution {
2
public:
3
int maxConsecutiveAnswers(string answerKey, int k) {
4
return max(helper(answerKey, k, 'T'), helper(answerKey, k, 'F'));
5
}
6

7
int helper(string answerKey, int k, char c) {
8
int start = 0;
9
int end = 0;
10
int count = 0;
11
int ans = 0;
12
while (end < answerKey.length()) {
13
if (answerKey[end] == c) count++;
14
while (count > k) {
15
if (answerKey[start] == c) count--;
16
start++;
17
}
18
ans = max(ans, end - start + 1);
19
end++;
20
}
21
return ans;
22
}
23
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0