Problem · String
Expand Given String
Learn this problemProblem statement
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.
Function
expandString(inputStr: String) → StringExamples
Example 1
inputStr = "(ab)(3)"return = "ababab"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".
Example 2
inputStr = "(ab)(3)(cd)(2)"return = "abababcdcd"In the given string S = "(ab)(3)(cd)(2)", P_1=ab, N_1=3 and P_2=cd, N_2=2.
Constraints
🥰More Cisco problems
- Collect CoinsSeen Jun 2025
- FizzBuzz ProblemSeen May 2025
- Find Largest Sum Contiguous SubarraySeen May 2025
- Find Largest Sum of Continuous SequenceSeen May 2025
- Find Palindrome Sub-stringSeen May 2025
- Count Numbers with Digit SumSeen Mar 2025
- Maximum Chocolates from Jars (L.C. 198 :)Seen Mar 2025
- Find Elements Largest in Row Smallest in ColumnSeen Mar 2025