Skip to content

Commit 7ffd308

Browse files
committed
Add 2024
1 parent 3e15ded commit 7ffd308

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@
611611
| 1971 | [Find if Path Exists in Graph](src/1971.find-if-path-exists-in-graph.py) | Easy | O(N) | O(N) | BFS, DFS, Graph | | |
612612
| 1974 | [Minimum Time to Type Word Using Special Typewriter](src/1974.minimum-time-to-type-word-using-special-typewriter.py) | Easy | O(N) | O(1) | String, Greedy | | |
613613
| 2000 | [Reverse Prefix of Word](src/2000.reverse-prefix-of-word.py) | Easy | O(N) | O(1) | Two Pointers, String | | |
614+
| 2024 | [Maximize the Confusion of an Exam](src/2024.maximize-the-confusion-of-an-exam.py) | Medium | O(N) | O(1) | String, Binary Search, Sliding Window, Prefix Sum | | |
614615
| 2039 | [The Time When the Network Becomes Idle](src/2039.the-time-when-the-network-becomes-idle.py) | Medium | O(V+E) | O(V+E) | Array, BFS, Graph | | |
615616
| 2042 | [Check if Numbers Are Ascending in a Sentence](src/2042.check-if-numbers-are-ascending-in-a-sentence.py) | Easy | O(N) | O(1) | String | | |
616617
| 2062 | [Count Vowel Substrings of a String](src/2062.count-vowel-substrings-of-a-string.py) | Easy | O(N^3) | O(N) | Hash Table, String | | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# @lc app=leetcode id=2024 lang=python3
3+
#
4+
# [2024] Maximize the Confusion of an Exam
5+
#
6+
7+
# @lc code=start
8+
# TAGS: String, Binary Search, Sliding Window, Prefix Sum
9+
class Solution:
10+
# 472 ms, 51.69%. Time and Space: O(N)
11+
def maxConsecutiveAnswers(self, answerKey: str, k: int) -> int:
12+
def get_optimal(answerKey, k, neg="F"):
13+
ans = ptr = 0
14+
for i, c in enumerate(answerKey):
15+
if c == neg:
16+
while not k:
17+
k += answerKey[ptr] == neg
18+
ptr += 1
19+
k -= 1
20+
ans = max(ans, i + 1 - ptr)
21+
return ans
22+
23+
return max(get_optimal(answerKey, k, neg="F"), get_optimal(answerKey, k, neg="T"))
24+
# @lc code=end

0 commit comments

Comments
 (0)