Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2968e76

Browse files
committed
Add solution #2024
1 parent 9f0110d commit 2968e76

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,693 LeetCode solutions in JavaScript
1+
# 1,694 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1552,6 +1552,7 @@
15521552
2019|[The Score of Students Solving Math Expression](./solutions/2019-the-score-of-students-solving-math-expression.js)|Hard|
15531553
2022|[Convert 1D Array Into 2D Array](./solutions/2022-convert-1d-array-into-2d-array.js)|Easy|
15541554
2023|[Number of Pairs of Strings With Concatenation Equal to Target](./solutions/2023-number-of-pairs-of-strings-with-concatenation-equal-to-target.js)|Medium|
1555+
2024|[Maximize the Confusion of an Exam](./solutions/2024-maximize-the-confusion-of-an-exam.js)|Medium|
15551556
2027|[Minimum Moves to Convert String](./solutions/2027-minimum-moves-to-convert-string.js)|Easy|
15561557
2033|[Minimum Operations to Make a Uni-Value Grid](./solutions/2033-minimum-operations-to-make-a-uni-value-grid.js)|Medium|
15571558
2037|[Minimum Number of Moves to Seat Everyone](./solutions/2037-minimum-number-of-moves-to-seat-everyone.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* 2024. Maximize the Confusion of an Exam
3+
* https://leetcode.com/problems/maximize-the-confusion-of-an-exam/
4+
* Difficulty: Medium
5+
*
6+
* A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting
7+
* false. He wants to confuse the students by maximizing the number of consecutive questions with
8+
* the same answer (multiple trues or multiple falses in a row).
9+
*
10+
* You are given a string answerKey, where answerKey[i] is the original answer to the ith question.
11+
* In addition, you are given an integer k, the maximum number of times you may perform the
12+
* following operation:
13+
* - Change the answer key for any question to 'T' or 'F' (i.e., set answerKey[i] to 'T' or 'F').
14+
*
15+
* Return the maximum number of consecutive 'T's or 'F's in the answer key after performing the
16+
* operation at most k times.
17+
*/
18+
19+
/**
20+
* @param {string} answerKey
21+
* @param {number} k
22+
* @return {number}
23+
*/
24+
var maxConsecutiveAnswers = function(answerKey, k) {
25+
const flipsLeft = k;
26+
const count = { T: 0, F: 0 };
27+
let result = 0;
28+
let left = 0;
29+
30+
for (let right = 0; right < answerKey.length; right++) {
31+
count[answerKey[right]]++;
32+
const maxCount = Math.max(count.T, count.F);
33+
34+
while (right - left + 1 - maxCount > flipsLeft) {
35+
count[answerKey[left]]--;
36+
left++;
37+
}
38+
39+
result = Math.max(result, right - left + 1);
40+
}
41+
42+
return result;
43+
};

0 commit comments

Comments
 (0)