Sliding Window Variable Subarrays Longer¶
Table of Contents¶
- 1358. Number of Substrings Containing All Three Characters (Medium)
- 2962. Count Subarrays Where Max Element Appears at Least K Times (Medium)
- 3325. Count Substrings With K-Frequency Characters I (Medium)
- 2799. Count Complete Subarrays in an Array (Medium)
- 2537. Count the Number of Good Subarrays (Medium)
- 3298. Count Substrings That Can Be Rearranged to Contain a String II (Hard)
- 2495. Number of Subarrays Having Even Product (Medium) 👑
1358. Number of Substrings Containing All Three Characters¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: hash table, string, sliding window
1358. Number of Substrings Containing All Three Characters - Python Solution
from collections import defaultdict
# Sliding Window Variable Size
def numberOfSubstrings(s: str) -> int:
freqs = defaultdict(int)
res = 0
left = 0
for right in range(len(s)):
freqs[s[right]] += 1
while len(freqs) == 3:
freqs[s[left]] -= 1
if freqs[s[left]] == 0:
del freqs[s[left]]
left += 1
res += left
return res
s = "abcabc"
print(numberOfSubstrings(s)) # 10
2962. Count Subarrays Where Max Element Appears at Least K Times¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, sliding window
3325. Count Substrings With K-Frequency Characters I¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: hash table, string, sliding window
2799. Count Complete Subarrays in an Array¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, hash table, sliding window
2537. Count the Number of Good Subarrays¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, hash table, sliding window
3298. Count Substrings That Can Be Rearranged to Contain a String II¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: hash table, string, sliding window
2495. Number of Subarrays Having Even Product¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, math, dynamic programming