반응형
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')
);
}
};
반응형
'Algorithm' 카테고리의 다른 글
LeetCode 863. All Nodes Distance K in Binary Tree (0) | 2023.07.11 |
---|---|
LeetCode 111. Minimum Depth of Binary Tree (0) | 2023.07.10 |
LeetCode 1493. Longest Subarray of 1's After Deleting One Element (0) | 2023.07.05 |
LeetCode 137. Single Number II (0) | 2023.07.05 |
LeetCode 859. Buddy Strings (0) | 2023.07.03 |