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¶
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