Given a string str of the type “3(ab)4(cd)”, the task is to expand it to “abababcdcdcdcd” where integers are from the range [1, 9].
This problem was asked in ThoughtWorks interview held in October 2018.
Input: str = “3(ab)4(cd)”
Input: str = “2(kl)3(ap)”
Approach: We traverse through the string and wait for a numeric value, num to turn up at position i. As soon as it arrives, we check i + 1 for a ‘(‘. If it’s present then program enters into a loop to extract whatever is within ‘(‘ and ‘)’ and concatenate it to an empty string, temp. Later another loop prints the generated string num number of times. Repeat these steps until the string finishes.
Below is the implementation of the approach:
- Java program to expand a String if range is given?
- Find the last remaining Character in the Binary String according to the given conditions
- Generate a string consisting of characters 'a' and 'b' that satisfy the given conditions
- Minimum number of substrings the given string can be splitted into that satisfy the given conditions
- Split the array into equal sum parts according to given conditions
- Count pairs of strings that satisfy the given conditions
- Find the longest sub-string which is prefix, suffix and also present inside the string
- String slicing in Python to check if a string can become empty by recursive deletion
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- String Range Queries to find the number of subsets equal to a given String
- Minimal moves to form a string by adding characters or appending string itself
- Create a new string by alternately combining the characters of two halves of the string in reverse
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Find the longest sub-string which is prefix, suffix and also present inside the string | Set 2
- Find length of longest subsequence of one string which is substring of another string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : SURENDRA_GANGWAR