Skip to content

Commit 693a11b

Browse files
committed
Apr 24
1 parent 6cd437e commit 693a11b

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 countCompleteSubarrays(self, nums: list[int]) -> int:
3+
n, distinct = len(nums), len(set(nums))
4+
ptr1, freqs, count = 0, {}, 0
5+
for ptr2 in range(n):
6+
freqs[nums[ptr2]] = freqs.get(nums[ptr2], 0) + 1
7+
while len(freqs) == distinct:
8+
count += n - ptr2
9+
freqs[nums[ptr1]] -= 1
10+
if freqs[nums[ptr1]] == 0:
11+
del freqs[nums[ptr1]]
12+
ptr1 += 1
13+
return count
14+
15+
16+
def main():
17+
nums = [1, 3, 1, 2, 2]
18+
assert Solution().countCompleteSubarrays(nums) == 4
19+
20+
nums = [5, 5, 5, 5]
21+
assert Solution().countCompleteSubarrays(nums) == 10
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
@@ -27,7 +27,7 @@
2727
| April 21 | [2145. Count the Hidden Sequences](https://leetcode.com/problems/count-the-hidden-sequences/) | Medium | Solved |
2828
| April 22 | [2338. Count the Number of Ideal Arrays](https://leetcode.com/problems/count-the-number-of-ideal-arrays/) | Hard | Unsolved |
2929
| April 23 | [1399. Count Largest Group](https://leetcode.com/problems/count-largest-group/) | Easy | Solved |
30-
| April 24 | []() | | |
30+
| April 24 | [2799. Count Complete Subarrays in an Array](https://leetcode.com/problems/count-complete-subarrays-in-an-array/) | Medium | Solved |
3131
| April 25 | []() | | |
3232
| April 26 | []() | | |
3333
| April 27 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 7 | 7 | 0 |
43-
| Medium | 12 | 9 | 3 |
43+
| Medium | 13 | 10 | 3 |
4444
| Hard | 4 | 0 | 4 |

0 commit comments

Comments
 (0)