Count Redundant Substrings Where Length Equals a*Vowels + b*Consonants
Given a string and two integers a and b, a substring is considered redundant if its length equals a * V + b * C, where V and C are the number of vowels and consonants in the substring respectively. Find the total count of redundant substrings within the given string.
Asked at:
Amazon
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late July, 2025
Amazon
Senior
An string is defined as redundant if the length of the string, |word| = a * V + b * C, where a and b are given integrers and V and C are the numbers of vowels and consonants in the string word. Given an string, and two integers, a, and b, find the number of redundant substrings of word. Note: A substring is a contiguous group of 0 or more characters in a string. Example: word = "abbacc", a=-1, b=2 The redundant substrings in "abbacc" are shown | Substring | Vowels | Consonants | Length | a * V + b * C | "abb" 1 2 3 -1*1 + 2*2 = 3 "bba" 1 2 3 -1*1 + 2*2 = 3 "bac" 1 2 3 -1*1 + 2*2 = 3 "acc" 1 2 3 -1*1 + 2*2 = 3 "abbacc" 2 4 6 -1*2 + 2*4 = 6 Constraints: 1 <= |word| <= 10^5 -10^3 <= a <= 10^3 -10^3 <= b <= 10^3 word contains lowercase English letters, [a-z]
Hello Interview Premium
Your account is free and you can post anonymously if you choose.