class Solution {
public int maxConsecutiveAnswers(String answerKey, int k) {
int res = 0;
int i = 0;
int count = 0;
for (int j = 0; j < answerKey.length(); ++j) {
if (answerKey.charAt(j) == 'T') {
res = Math.max(res, j - i + 1);
} else {
++count;
while (count > k) {
if (answerKey.charAt(i) == 'F') {
--count;
}
++i;
}
res = Math.max(res, j - i + 1);
}
}
i = 0;
count = 0;
for (int j = 0; j < answerKey.length(); ++j) {
if (answerKey.charAt(j) == 'F') {
res = Math.max(res, j - i + 1);
} else {
++count;
while (count > k) {
if (answerKey.charAt(i) == 'T') {
--count;
}
++i;
}
res = Math.max(res, j - i + 1);
}
}
return res;
}
}