leetcode

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

commit 0c75ff87e2e5161d1b87351dbed2148f5100771c
parent 3fed476d3c5decfc742040e818812c54fab4ce57
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon,  2 Sep 2024 21:42:17 +0200

Daily Problem

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

diff --git a/Problems/1894.cpp b/Problems/1894.cpp @@ -0,0 +1,16 @@ +class Solution { + public: + int chalkReplacer(const vector<int> &chalk, int k) const { + const long long sum = accumulate(begin(chalk), end(chalk), 0ll); + int n = 0; + + k %= sum; + while (true) { + if (k < chalk[n]) return n; + k -= chalk[n]; + n = (n + 1) % size(chalk); + } + + return -1; + } +}; diff --git a/README.md b/README.md @@ -1024,6 +1024,7 @@ for solving problems. | 1884 | Medium | [Egg Drop With 2 Eggs and N Floors](Problems/1884.cpp) | | 1887 | Medium | [Reduction Operations to Make the Array Elements Equal](Problems/1887.cpp) | | 1890 | Easy | [The Latest Login in 2020](Problems/1890.cpp) | +| 1894 | Medium | [Find the Student that Will Replace the Chalk](Problems/1894.cpp) | | 1895 | Medium | [Largest Magic Square](Problems/1895.cpp) | | 1897 | Easy | [Redistribute Characters to Make All Strings Equal](Problems/1897.cpp) | | 1899 | Medium | [Merge Triplets to Form Target Triplet](Problems/1899.cpp) |