leetcode

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

commit d7b4c9307428ab7e40cc1da93fce311210572d8f
parent 1a59eeed000853873f72a66783c005caf3508552
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Thu, 27 Jul 2023 17:55:39 +0200

Daily Problem

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

diff --git a/Problems/2141.cpp b/Problems/2141.cpp @@ -0,0 +1,16 @@ +class Solution { +public: + long long maxRunTime(int n, const vector<int> &batteries) { + long long low = 1, + high = reduce(batteries.begin(), batteries.end(), 0LL) / n; + while (low < high) { + long long mid = high - (high - low) / 2, sum = 0; + for (long long bat : batteries) sum += min(bat, mid); + if (sum >= (long long)(n * mid)) + low = mid; + else + high = mid - 1; + } + return low; + } +}; diff --git a/README.md b/README.md @@ -554,6 +554,7 @@ for solving problems. | 2130 | Medium | [Maximum Twin Sum of a Linked List](Problems/2130.cpp) | | 2131 | Medium | [Longest Palindrome by Concatenating Two Letter Words](Problems/2131.cpp) | | 2140 | Medium | [Solving Questions With Brainpower](Problems/2140.cpp) | +| 2141 | Hard | [Maximum Running Time of N Computers](Problems/2141.cpp) | | 2177 | Medium | [Find Three Consecutive Integers That Sum to a Given Number](Problems/2177.cpp) | | 2181 | Medium | [Merge Nodes in Between Zeros](Problems/2181.cpp) | | 2187 | Medium | [Minimum Time to Complete Trips](Problems/2187.cpp) |