Search
⌘K

Leetcode 2949. Count Beautiful Substrings II

Count the non-empty substrings where vowels == consonants and their product is divisible by k; since equality implies length 2t with t vowels, the problem reduces to counting substrings of length 2t that contain exactly t vowels for every t with t^2 % k == 0. Efficient solutions combine enumerating valid t (up to n/2) with prefix sums or sliding-window counting to handle strings up to 5·10^4.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.