commit 3dcd6ec653682dc30a0c923ad5976056a5ee3d2f
parent 4eba76cf87b984de24105cd5516587543be95faf
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Thu, 16 May 2024 10:51:27 +0200
1 Random Problem
Diffstat:
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/Problems/2766.cpp b/Problems/2766.cpp
@@ -0,0 +1,22 @@
+class Solution {
+ public:
+ vector<int> relocateMarbles(const vector<int> &nums, const vector<int> &moveFrom,
+ const vector<int> &moveTo) const {
+ unordered_map<int, int> um;
+ vector<int> res;
+
+ for (const int num : nums)
+ um[num]++;
+ for (int i = 0; i < size(moveFrom); i++) {
+ if (moveTo[i] == moveFrom[i]) continue;
+ um[moveTo[i]] += um[moveFrom[i]];
+ um[moveFrom[i]] = 0;
+ }
+
+ for (const auto [k, v] : um)
+ if (v) res.push_back(k);
+ sort(begin(res), end(res));
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -1189,6 +1189,7 @@ for solving problems.
| 2740 | Medium | [Find the Value of the Partition](Problems/2740.cpp) |
| 2742 | Hard | [Painting the Walls](Problems/2742.cpp) |
| 2745 | Medium | [Construct the Longest New String](Problems/2745.cpp) |
+| 2766 | Medium | [Relocate Marbles](Problems/2766.cpp) |
| 2767 | Medium | [Partition String Into Minimum Beautiful Substrings](Problems/2767.cpp) |
| 2780 | Medium | [Minimum Index of a Valid Split](Problems/2780.cpp) |
| 2785 | Medium | [Sort Vowels in a String](Problems/2785.cpp) |