Skip to content

Commit c592d95

Browse files
committed
Apr 29
1 parent 51e1e2e commit c592d95

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def countSubarrays(self, nums: list[int], k: int) -> int:
3+
max_ = max(nums)
4+
ptr1, curr, count = 0, 0, 0
5+
for ptr2 in range(len(nums)):
6+
curr += nums[ptr2] == max_
7+
while curr >= k:
8+
curr -= nums[ptr1] == max_
9+
ptr1 += 1
10+
count += ptr1
11+
return count
12+
13+
14+
def main():
15+
nums = [1, 3, 2, 3, 3]
16+
k = 2
17+
assert Solution().countSubarrays(nums, k) == 6
18+
19+
nums = [1, 4, 2, 1]
20+
k = 3
21+
assert Solution().countSubarrays(nums, k) == 0
22+
23+
24+
if __name__ == '__main__':
25+
main()

2025-04-April-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
| April 26 | [2444. Count Subarrays With Fixed Bounds](https://leetcode.com/problems/count-subarrays-with-fixed-bounds/) | Hard | Unsolved |
3333
| April 27 | [3392. Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/) | Easy | Solved |
3434
| April 28 | [2302. Count Subarrays With Score Less Than K](https://leetcode.com/problems/count-subarrays-with-score-less-than-k/) | Hard | Solved |
35-
| April 29 | []() | | |
35+
| April 29 | [2962. Count Subarrays Where Max Element Appears at Least K Times](https://leetcode.com/problems/count-subarrays-where-max-element-appears-at-least-k-times/) | Medium | Solved |
3636
| April 30 | []() | | |
3737

3838

3939
## Summary
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 8 | 8 | 0 |
43-
| Medium | 13 | 9 | 4 |
43+
| Medium | 14 | 10 | 4 |
4444
| Hard | 6 | 1 | 5 |

0 commit comments

Comments
 (0)