Get Redundant Substrings
Learn this problemProblem statement
Data analysts at Amazon are building a utility to identify redundant words in advertisements.
They define a string as redundant if the length of the string, |word| = a * V + b * C, where a and b are given integers and V and C are the numbers of vowels and consonants in the string. Note that for any substring, |word| = V + C, so a substring is redundant when V + C = a * V + b * C.
Given a string word, and two integers a and b, find the number of redundant substrings of word.
A substring is a contiguous, non-empty group of characters in a string. For example, "bcb" is a substring of "abcba", while "bba" is not. The empty substring is not counted.
Vowels are the letters a, e, i, o, u; all other lowercase English letters are consonants.
Function
getRedundantSubstrings(word: String, a: int, b: int) → intComplete the function getRedundantSubstrings in the editor below.
Returns
int: the number of redundant substrings
Examples
Example 1
word = "abbacc"a = -1b = 2return = 5Example 2
word = "akljfs"a = -2b = 1return = 15Constraints
1 ≤ |word| ≤ 10^5-10^3 ≤ a ≤ 10^3-10^3 ≤ b ≤ 10^3wordcontains lowercase English letters,[a-z].
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026