leetcode

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

commit 43747ad4054b3742f2845f849b010416973925b2
parent b7b5fc681ddc1c0c7ff307680ac29ebf49508950
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Thu, 27 Jun 2024 10:53:02 +0200

1 Random Problem

Diffstat:
AProblems/1419.cpp | 20++++++++++++++++++++
MREADME.md | 1+
2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/Problems/1419.cpp b/Problems/1419.cpp @@ -0,0 +1,20 @@ +class Solution { + public: + int minNumberOfFrogs(const string &croakOfFrogs) const { + static const string word = "croak"; + int count[5] = {0}, frogs = 0, res = 0; + + for (const char c : croakOfFrogs) { + const int idx = word.find(c); + if (idx == 0) + res = max(res, ++frogs); + else if (!count[idx - 1]--) + return -1; + else if (idx == 4) + frogs--; + count[idx]++; + } + + return !frogs ? res : -1; + } +}; diff --git a/README.md b/README.md @@ -809,6 +809,7 @@ for solving problems. | 1415 | Medium | [The k-th Lexicographical String of All Happy Strings of Length n](Problems/1415.cpp) | | 1416 | Hard | [Restore The Array](Problems/1416.cpp) | | 1418 | Medium | [Display Table of Food Orders in a Restaurant](Problems/1418.cpp) | +| 1419 | Medium | [Minimum Number of Frogs Croaking](Problems/1419.cpp) | | 1420 | Hard | [Build Array Where You Can Find The Maximum Exactly K Comparisons](Problems/1420.cpp) | | 1422 | Easy | [Maximum Score After Splitting a String](Problems/1422.cpp) | | 1423 | Medium | [Maximum Points You Can Obtain from Cards](Problems/1423.cpp) |