FastPrepFastPrep
Problem Brief

Expand Given String

INTERNOA
See Cisco online assessment and hiring insights

Write an algorithm to expand the given string by using the given rules.

Input

The input consists of a string - inputStr, representing the substring(s) grouped by using parenthesis (S).

Output

Print the string by expanding it in such a way that P will be concatenated with itself N_n times to expand.

༘⋆🌷🫧 Credit to Charlotte˚ෆ

1Example 1

Input
inputStr = "(ab)(3)"
Output
"ababab"
Explanation

In the given string S = "(ab)(3)", P_1=ab, N_1=3. So, to expand string S, pattern P_1 will be concatenated N_1 times as "ab" + "ab" + "ab" to give the final output. So, the output is "ababab".

2Example 2

Input
inputStr = "(ab)(3)(cd)(2)"
Output
"abababcdcd"
Explanation

In the given string S = "(ab)(3)(cd)(2)", P_1=ab, N_1=3 and P_2=cd, N_2=2.

Constraints

Limits and guarantees your solution can rely on.

🥰
public String expandString(String inputStr) {
  // write your code here
}
Input

inputStr

"(ab)(3)"

Output

"ababab"

Sign in to submit your solution.