leetcode

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

commitc7a29829ceddc7bb16a29e2fdc0fd8f7e0cb4bca
parentdb17af74f6e01d983ba278bd273e8f8c8a7a92e6
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateSun, 22 Oct 2023 21:57:49 +0000

Daily Problem

Diffstat:
AProblems/1793.cpp|++++++++++++++
MREADME.md|+

2 files changed, 15 insertions(+), 0 deletions(-)


diff --git a/Problems/1793.cpp b/Problems/1793.cpp

@@ -0,0 +1,14 @@

class Solution {
public:
int maximumScore(const vector<int> &nums, int k) {
const int n = nums.size();
int left = k - 1, right = k + 1, res = nums[k], mini = nums[k];
while (left >= 0 || right < n) {
const int a = left >= 0 ? nums[left] : 0;
const int b = right < n ? nums[right] : 0;
mini = min(mini, a < b ? nums[right++] : nums[left--]);
res = max(res, mini * (right - left - 1));
}
return res;
}
};

diff --git a/README.md b/README.md

@@ -712,6 +712,7 @@ for solving problems.

| 1781 | Medium | [Sum of Beauty of All Substrings](Problems/1781.cpp) |
| 1786 | Medium | [Number of Restricted Paths From First to Last Node](Problems/1786.cpp) |
| 1791 | Easy | [Find Center of Star Graph](Problems/1791.cpp) |
| 1793 | Hard | [Maximum Score of a Good Subarray](Problems/1793.cpp) |
| 1799 | Medium | [Maximize Score After N Operations](Problems/1799.cpp) |
| 1802 | Medium | [Maximum Value at a Given Index in a Bounded Array](Problems/1802.cpp) |
| 1806 | Medium | [Minimum Number of Operations to Reinitialize a Permutation](Problems/1806.cpp) |