leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 0b21a92e31935b3f3b65f45f74b4231b96d9d72d
parent a81aa3cfaf905d84ac6f27739d1c8367b34d5ff9
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri,  7 Jul 2023 10:02:34 +0200

Daily Problem

Diffstat:
AProblems/2024.cpp | 16++++++++++++++++
MREADME.md | 1+
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/Problems/2024.cpp b/Problems/2024.cpp @@ -0,0 +1,16 @@ +class Solution { +public: + int maxConsecutiveAnswers(string answerKey, int k) { + int i = 0, j = 0, res = 0, t = 0, f = 0; + while (true) { + if (min(t, f) <= k) { + if (j == answerKey.size()) break; + (answerKey[j++] == 'T' ? t : f)++; + } else { + res = max(res, j - i); + (answerKey[i++] == 'T' ? t : f)--; + } + } + return max(res - 1, j - i); + } +}; diff --git a/README.md b/README.md @@ -530,6 +530,7 @@ for solving problems. | 1971 | Easy | [Find if Path Exists in Graph](Problems/1971.cpp) | | 1976 | Medium | [Number of Ways to Arrive at Destination](Problems/1976.cpp) | | 1991 | Easy | [Find the Middle Index in Array](Problems/1991.cpp) | +| 2024 | Medium | [Maximize the Confusion of an Exam](Problems/2024.cpp) | | 2039 | Medium | [The Time When the Network Becomes Idle](Problems/2039.cpp) | | 2073 | Easy | [Time Needed to Buy Tickets](Problems/2073.cpp) | | 2085 | Easy | [Count Common Words With One Occurrence](Problems/2085.cpp) |