leetcode

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

commit 517068125b2d587cff41957dfe11480c46048b64
parent 9ed9c25cd8954b88019c6d7dfd92996cf1889f5f
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Sat, 14 Dec 2024 12:36:42 +0100

Daily Problem

Diffstat:
A Problems/2762.cpp | +++++++++++++++++++++
M README.md | +

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


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

@@ -0,0 +1,21 @@
class Solution {
public:
long long continuousSubarrays(const vector<int> &nums) const {
const int n = size(nums);
long long res = 0;
map<int, int> mp;
for (int i = 0, j = 0; j < n; j++) {
mp[nums[j]]++;
while (mp.rbegin()->first - mp.begin()->first > 2) {
const int crnt = nums[i++];
if (!--mp[crnt]) mp.erase(crnt);
}
res += j - i + 1;
}
return res;
}
};

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

@@ -1413,6 +1413,7 @@ reference and a base for solving problems. | 2742 | Hard | [Painting the Walls](Problems/2742.cpp) | | 2745 | Medium | [Construct the Longest New String](Problems/2745.cpp) | | 2751 | Hard | [Robot Collisions](Problems/2751.cpp) |
| 2762 | Medium | [Continuous Subarrays](Problems/2762.cpp) |
| 2766 | Medium | [Relocate Marbles](Problems/2766.cpp) | | 2767 | Medium | [Partition String Into Minimum Beautiful Substrings](Problems/2767.cpp) | | 2769 | Easy | [Find the Maximum Achievable Number](Problems/2769.cpp) |