leetcode

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

commite0e64c5c40cd7951eb4e64bdaad85ad90ffffb99
parentc6717caa4cfca3b3ed10ea3c4bb2862da128e97a
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateThu, 28 Mar 2024 18:29:10 +0000

Daily Problem

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

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


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

@@ -0,0 +1,16 @@

class Solution {
public:
long long countSubarrays(const vector<int> &nums, int k) const {
int maxi = *max_element(begin(nums), end(nums));
long long res = 0;
for (int i = 0, j = 0, crnt = 0; j < size(nums); j++) {
if (nums[j] == maxi) crnt++;
while (crnt >= k)
if (nums[i++] == maxi) crnt--;
res += i;
}
return res;
}
};

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

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

| 2947 | Medium | [Count Beautiful Substrings I](Problems/2947.cpp) |
| 2952 | Medium | [Minimum Number of Coins to be Added](Problems/2952.cpp) |
| 2958 | Medium | [Length of Longest Subarray With at Most K Frequency](Problems/2958.cpp) |
| 2962 | Medium | [Count Subarrays Where Max Element Appears at Least K Times](Problems/2962.cpp) |
| 2966 | Medium | [Divide Array Into Arrays With Max Difference](Problems/2966.cpp) |
| 2971 | Medium | [Find Polygon With the Largest Perimeter](Problems/2971.cpp) |
| 2997 | Medium | [Minimum Number of Operations to Make Array XOR Equal to K](Problems/2997.cpp) |