FastPrepDecode Repeated Groups

Decode Repeated Groups

Waymo logoWaymo● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Complete the function below. The function receives the full standard input as a single string and returns the exact standard output lines.

Problem Decode strings that contain repeated parenthesized groups. Plain characters are copied directly. A group has the form (substring){k}, meaning the decoded substring inside the parentheses is repeated k times. Groups may be nested.

For each encoded string, output its decoded form.

Function

solveDecodeRepeatedGroups(input: String) → String[]

Complete solveDecodeRepeatedGroups. It has one parameter, String input. The first line is q, followed by q encoded strings. Return one decoded string per query.

Examples

Example 1

input = "3\nabs(cs){3}g\na(b(c){2}){2}\nx(yz){0}q"return = ["abscscscsg","abccbcc","xq"]

The second case decodes the nested group b(c){2} as bcc, then repeats it twice.

Constraints

  • Repeat counts are non-negative integers written inside braces after a closing parenthesis.
  • Parentheses and braces are balanced in valid inputs.

More Waymo problems

See Waymo hiring insights
public String[] solveDecodeRepeatedGroups(String input) {
    // write your code here
}
input"3\nabs(cs){3}g\na(b(c){2}){2}\nx(yz){0}q"
expected["abscscscsg", "abccbcc", "xq"]
Checking account…