leetcode

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

commit ea856cdd5f2aef7e5e0c55e230965b83312d45be
parent 07bc4982f52d8f67211b5cc2fcf25dda972dcf58
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 29 Mar 2023 15:57:11 +0200

Daily Problem

Diffstat:
AProblems/1402.cpp | 12++++++++++++
MREADME.md | 1+
2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/Problems/1402.cpp b/Problems/1402.cpp @@ -0,0 +1,12 @@ +class Solution { +public: + int maxSatisfaction(vector<int> &satisf) { + sort(satisf.begin(), satisf.end()); + if (satisf.back() <= 0) return 0; + + int j = satisf.size() - 1, crnt = 0, sum = 0, res = 0; + for (; j >= 0; j--) res = max(res, crnt += sum += satisf[j]); + + return res; + } +}; diff --git a/README.md b/README.md @@ -416,6 +416,7 @@ for solving problems. | 1373 | Hard | [Maximum Sum BST in Binary Tree](Problems/1373.cpp) | | 1379 | Easy | [Find a Corresponding Node of a Binary Tree in a Clone of That Tree](Problems/1379.cpp) | | 1382 | Medium | [Balance a Binary Search Tree](Problems/1382.cpp) | +| 1402 | Hard | [Reducing Dishes](Problems/1402.cpp) | | 1425 | Hard | [Constrained Subsequence Sum](Problems/1425.cpp) | | 1436 | Easy | [Destination City](Problems/1436.cpp) | | 1438 | Medium | [Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit](Problems/1438.cpp) |