commit a4e4d22fff05316e4dd1eb0ab54f246c9d4780b2
parent 3ccbd3c0cae091b272478445ccc427a820415346
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Mon, 1 Apr 2024 14:01:09 +0000
1 Random Problem
Diffstat:
2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/Problems/2342.cpp b/Problems/2342.cpp
@@ -0,0 +1,25 @@
+class Solution {
+ static int sum_digits(int n) {
+ int res = 0;
+ while (n)
+ res += n % 10, n /= 10;
+ return res;
+ }
+
+ public:
+ int maximumSum(const vector<int> &nums) const {
+ static int um[82];
+ int res = -1;
+
+ memset(um, 0x00, sizeof(um));
+ for (const int num : nums) {
+ const int sum = sum_digits(num);
+ if (um[sum])
+ res = max(res, num + um[sum]), um[sum] = max(um[sum], num);
+ else
+ um[sum] = num;
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -1183,3 +1183,4 @@ for solving problems.
| 3039 | Medium | [Apply Operations to Make String Empty](Problems/3039.cpp) |
| 3070 | Medium | [Count Submatrices with Top-Left Element and Sum Less Than k](Problems/3070.cpp) |
| 3101 | Medium | [Count Alternating Subarrays](Problems/3101.cpp) |
+| 2342 | Medium | [Max Sum of a Pair With Equal Sum of Digits](Problems/2342.cpp) |