3210. Count Beautiful Substrings I
My accepted Python solution to LeetCode problem 3210, Count Beautiful Substrings I, running in 839ms.
- Difficulty: Medium
- Python
- Runtime 839ms
- Memory 17.7MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 839ms, memory 17.7MB, accepted 2026-01-01.
class Solution:
def beautifulSubstrings(self, s: str, k: int) -> int:
vowels = set('aeiou')
n = len(s)
count = 0
for i in range(n):
v = 0 # vowel count
c = 0 # consonant count
for j in range(i, n):
if s[j] in vowels:
v += 1
else:
c += 1
if v == c and (v * c) % k == 0:
count += 1
return count