FastPrepFastPrep
Problem Brief

Decode Repeated Groups

FULLTIMEPHONE SCREEN

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 Description

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

1Example 1

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

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

Constraints

Limits and guarantees your solution can rely on.

Repeat counts are non-negative integers written inside braces after a closing parenthesis.

Parentheses and braces are balanced in valid inputs.

public String[] solveDecodeRepeatedGroups(String input) {
    // write your code here
}
Input

input

"3\nabs(cs){3}g\na(b(c){2}){2}\nx(yz){0}q"

Output

["abscscscsg", "abccbcc", "xq"]

Sign in to submit your solution.