FastPrepFastPrep
Problem Brief

Get Redundant Substrings

FULLTIMEOA
See Amazon online assessment and hiring insights

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 word.

Given a string word, 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. For example- "bcb" is a substring of "abcba", while "bba" is not.

Function Description

Complete the function getRedundantSubstrings in the editor below.

Returns

int: the number of redundant substrings

1Example 1

Input
word = "abbacc", a = -1, b = 2
Output
5
Explanation
Example 1 illustration
There are 5 redundant substrings.

2Example 2

Input
word = "akljfs", a = -2, b = 1
Output
15
Explanation
N/A for now...Will add once fint it :) Or if you happen to know about it, feel free to lmk! Manyyy thanks in advance! 😘

Constraints

Limits and guarantees your solution can rely on.

  1. 1 ≤ |word| ≤ 10^5
  2. -10^3 ≤ a ≤ 10^3
  3. -10^3 ≤ b ≤ 10^3
  4. word contains lowercase English letters, [a-z].
public int getRedundantSubstrings(String word, int a, int b) {
  // write your code here
}
Input

word

"abbacc"

a

-1

b

2

Output

5

Sign in to submit your solution.