leetcode

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

commitc15945ee7151880053e6b5921bc329d6025833b8
parent9276bc698adfdf18fb16c9902f410e91508bde24
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateWed, 19 Jun 2024 19:13:55 +0200

1 Random Problem

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

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


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

@@ -0,0 +1,30 @@

class FindSumPairs {
unordered_map<int, int> count1, count2;
vector<int> arr;
public:
FindSumPairs(const vector<int> &nums1, const vector<int> &nums2) : arr(nums2) {
for (const int n : nums1)
count1[n]++;
for (const int n : nums2)
count2[n]++;
}
void add(int index, int val) {
count2[arr[index]]--;
arr[index] += val;
count2[arr[index]]++;
}
int count(int tot) const {
int res = 0;
for (const auto [k, v] : count1) {
const auto it = count2.find(tot - k);
if (!v || it == count2.end()) continue;
res += v * it->second;
}
return res;
}
};

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

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

| 1860 | Medium | [Incremental Memory Leak](Problems/1860.cpp) |
| 1861 | Medium | [Rotating the Box](Problems/1861.cpp) |
| 1863 | Easy | [Sum of All Subset XOR Totals](Problems/1863.cpp) |
| 1865 | Medium | [Finding Pairs With a Certain Sum](Problems/1865.cpp) |
| 1870 | Medium | [Minimum Speed to Arrive on Time](Problems/1870.cpp) |
| 1873 | Easy | [Calculate Special Bonus](Problems/1873.cpp) |
| 1877 | Medium | [Minimize Maximum Pair Sum in Array](Problems/1877.cpp) |