leetcode

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

commit cc043aa2a286a0b70ef2bfb3c69110370a562617
parent e0e64c5c40cd7951eb4e64bdaad85ad90ffffb99
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri, 29 Mar 2024 21:32:46 +0000

1 Random Problem

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

diff --git a/Problems/1423.cpp b/Problems/1423.cpp @@ -0,0 +1,17 @@ +class Solution { + public: + int maxScore(const vector<int> &cardPoints, int k) const { + const int n = size(cardPoints); + + int res = 0, sum = 0; + for (int i = 0; i < k; i++) + sum += cardPoints[i]; + for (int i = n, j = k - 1; j >= 0; i--, j--) { + res = max(res, sum); + sum += cardPoints[i - 1]; + sum -= cardPoints[j]; + } + + return max(res, sum); + } +}; diff --git a/README.md b/README.md @@ -766,6 +766,7 @@ for solving problems. | 1418 | Medium | [Display Table of Food Orders in a Restaurant](Problems/1418.cpp) | | 1420 | Hard | [Build Array Where You Can Find The Maximum Exactly K Comparisons](Problems/1420.cpp) | | 1422 | Easy | [Maximum Score After Splitting a String](Problems/1422.cpp) | +| 1423 | Medium | [Maximum Points You Can Obtain from Cards](Problems/1423.cpp) | | 1424 | Medium | [Diagonal Traverse II](Problems/1424.cpp) | | 1425 | Hard | [Constrained Subsequence Sum](Problems/1425.cpp) | | 1431 | Easy | [Kids With the Greatest Number of Candies](Problems/1431.cpp) |