Skip to content

Commit cf2f603

Browse files
committed
Apr 16
1 parent f219af0 commit cf2f603

File tree

2 files changed

+29
-2
lines changed

2 files changed

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
| April 13 | [1922. Count Good Numbers](https://leetcode.com/problems/count-good-numbers/) | Medium | Unsolved |
2020
| April 14 | [1534. Count Good Triplets](https://leetcode.com/problems/count-good-triplets/) | Easy | Solved |
2121
| April 15 | [2179. Count Good Triplets in an Array](https://leetcode.com/problems/count-good-triplets-in-an-array/) | Hard | Unsolved |
22-
| April 16 | []() | | |
22+
| April 16 | [2537. Count the Number of Good Subarrays](https://leetcode.com/problems/count-the-number-of-good-subarrays/) | Medium | Unsolved |
2323
| April 17 | []() | | |
2424
| April 18 | []() | | |
2525
| April 19 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 5 | 5 | 0 |
43-
| Medium | 7 | 5 | 2 |
43+
| Medium | 8 | 5 | 3 |
4444
| Hard | 3 | 0 | 3 |

0 commit comments

Comments
 (0)