leetcode

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

commit ac6c249437469f785c2af42c18cf99309cf82b3a
parent bd226acde6fe111626dd2dcede6643b41314ae06
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sun,  2 Apr 2023 18:32:55 +0200

Daily Problem

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

diff --git a/Problems/2300.cpp b/Problems/2300.cpp @@ -0,0 +1,15 @@ +class Solution { +public: + vector<int> successfulPairs(vector<int> &spells, vector<int> &potions, + long long success) { + sort(potions.begin(), potions.end()); + + vector<int> res; + for (int i = 0; i < spells.size(); i++) { + auto it = lower_bound(potions.begin(), potions.end(), + ceil(success / (double)spells[i])); + res.push_back(potions.end() - it); + } + return res; + } +}; diff --git a/README.md b/README.md @@ -480,6 +480,7 @@ for solving problems. | 2265 | Medium | [Count Nodes Equal to Average of Subtree](Problems/2265.cpp) | | 2279 | Medium | [Maximum Bags With Full Capacity of Rocks](Problems/2279.cpp) | | 2285 | Medium | [Maximum Total Importance of Roads](Problems/2285.cpp) | +| 2300 | Medium | [Successful Pairs of Spells and Potions](Problems/2300.cpp) | | 2306 | Hard | [Naming a Company](Problems/2306.cpp) | | 2316 | Medium | [Count Unreachable Pairs of Nodes in an Undirected Graph](Problems/2316.cpp) | | 2326 | Medium | [Spiral Matrix IV](Problems/2326.cpp) |