Count Beautiful Substrings II

You are given a string s and a positive integer k.

Let vowels and consonants be the number of vowels and consonants in a string.

A string is beautiful if:

  • vowels == consonants.
  • (vowels * consonants) % k == 0; in other terms, the multiplication of vowels and consonants is divisible by k.

Return the number of non-empty beautiful substrings in the given string s.

A substring is a contiguous sequence of characters in a string.

Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.

Consonant letters in English are every letter except vowels.

Example 1
Inputs = "baeyh", k = 2
Output2
There are exactly 2 beautiful substrings in s: aeyh and baey.
Example 2
Inputs = "abba", k = 1
Output3
There are exactly 3 beautiful substrings in s.

Constraints

  • 1 <= s.length <= 5 * 10^4
  • 1 <= k <= 1000
  • s consists of only English lowercase letters.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate