Skip to content

Commit 26c177d

Browse files
authored
Create 2024-maximize-the-confusion-of-an-exam.js
1 parent ac59868 commit 26c177d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {string} answerKey
3+
* @param {number} k
4+
* @return {number}
5+
*/
6+
const maxConsecutiveAnswers = function(answerKey, k) {
7+
const helper = (str, transT) => {
8+
let res = 0, l = 0, r = 0, num = 0
9+
const n = str.length
10+
const target = transT === 1 ? 'T' : 'F'
11+
while(r < n) {
12+
if(str[r] === target) num++
13+
while(num > k) {
14+
if(str[l] === target) num--
15+
l++
16+
}
17+
res = Math.max(res, r - l + 1)
18+
r++
19+
}
20+
return res
21+
}
22+
23+
return Math.max(helper(answerKey, 0), helper(answerKey, 1))
24+
};
25+

0 commit comments

Comments
 (0)