leetcode

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

commit 50ceb6cb139a852ef23cb85c23d7940474c2c499
parent ff0a26a04244dca9e4973c958dc92f3751aed48e
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri,  7 Jun 2024 15:28:00 +0200

1 Random Problem

Diffstat:
AProblems/1482.cpp | 29+++++++++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/Problems/1482.cpp b/Problems/1482.cpp @@ -0,0 +1,29 @@ +class Solution { + static bool possible(const vector<int> &bloomDay, int m, int k, int n) { + int adj = 0; + + for (const auto day : bloomDay) { + adj = day <= n ? adj + 1 : 0; + if (adj == k) adj = 0, m--; + } + + return m <= 0; + } + + public: + int minDays(const vector<int> &bloomDay, int m, int k) const { + if ((long long)m * k > size(bloomDay)) return -1; + + int low = 1, high = *max_element(begin(bloomDay), end(bloomDay)); + + while (low < high) { + const int mid = low + (high - low) / 2; + if (possible(bloomDay, m, k, mid)) + high = mid; + else + low = mid + 1; + } + + return low; + } +}; diff --git a/README.md b/README.md @@ -828,6 +828,7 @@ for solving problems. | 1476 | Medium | [Subrectangle Queries](Problems/1476.cpp) | | 1480 | Easy | [Running Sum of 1d Array](Problems/1480.cpp) | | 1481 | Medium | [Least Number of Unique Integers after K Removals](Problems/1481.cpp) | +| 1482 | Medium | [Minimum Number of Days to Make m Bouquets](Problems/1482.cpp) | | 1484 | Easy | [Group Sold Products By The Date](Problems/1484.cpp) | | 1489 | Hard | [Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree](Problems/1489.cpp) | | 1491 | Easy | [Average Salary Excluding the Minimum and Maximum Salary](Problems/1491.cpp) |