leetcode

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

commit 38025ba13dc953105bf207696885e21cdd7d122d
parent e4f1cf77688f1215190d0ea580edb0a2301d26b8
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sun, 19 May 2024 23:33:50 +0200

Daily Problem

Diffstat:
AProblems/3068.cpp | 24++++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/Problems/3068.cpp b/Problems/3068.cpp @@ -0,0 +1,24 @@ +class Solution { + public: + long long maximumValueSum(const vector<int> &nums, int k, const vector<vector<int>> &edges) const { + int count = 0, mini = INT_MAX, maxi = INT_MIN; + long long total = 0; + + for (const int val : nums) { + const int after = val ^ k; + const int change = after - val; + total += val; + + if (change > 0) { + mini = min(mini, change); + total += change; + count++; + } else { + maxi = max(maxi, change); + } + } + + if (count % 2 == 0) return total; + return max(total - mini, total + maxi); + } +}; diff --git a/README.md b/README.md @@ -1225,6 +1225,7 @@ for solving problems. | 3034 | Medium | [Number of Subarrays That Match a Pattern I](Problems/3034.cpp) | | 3039 | Medium | [Apply Operations to Make String Empty](Problems/3039.cpp) | | 3067 | Medium | [Count Pairs of Connectable Servers in a Weighted Tree Network](Problems/3067.cpp) | +| 3068 | Hard | [Find the Maximum Sum of Node Values](Problems/3068.cpp) | | 3070 | Medium | [Count Submatrices with Top-Left Element and Sum Less Than k](Problems/3070.cpp) | | 3075 | Medium | [Maximize Happiness of Selected Children](Problems/3075.cpp) | | 3100 | Medium | [Water Bottles II](Problems/3100.cpp) |