Requirements
- Input is one string
inputStr. - A pattern is a substring enclosed in parentheses, followed by a repeat count enclosed in curly braces.
- Expand each pattern by concatenating it with itself the requested number of times.
- Pattern-count pairs can be nested, such as
(ef((ab){2}cd){2}){2}. - Multi-digit counts can appear.
- Some inputs may contain spaces; skip irrelevant spaces if the statement permits them.
Examples
Input:
(ab){3}
Output:
ababab
Input:
(a(bc){2}){2}
Output:
abcbcabcbc
Notes
- A stack-based parser is the natural fit: keep the string accumulated before
(, parse the substring up to), read the following{number}, then repeat and append. - Java candidates hit errors when comparing
chartoString, for example using!= "}"instead of comparing against'}'. - Hidden cases can stress nested groups and multi-digit repeat counts.

