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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Change the given string according to the given conditions
- Find the last remaining Character in the Binary String according to the given conditions
- Split the array into equal sum parts according to given conditions
- Count of ways to traverse a Matrix according to given conditions
- Java program to expand a String if range is given?
- Given a string and an integer k, find the kth sub-string when all the sub-strings are sorted according to the given condition
- Minimum number of substrings the given string can be splitted into that satisfy the given conditions
- Generate a String from given Strings P and Q based on the given conditions
- Reverse the substrings of the given String according to the given Array of indices
- Sort a string according to the order defined by another string
- Generate a string consisting of characters 'a' and 'b' that satisfy the given conditions
- Generate a string from an array of alphanumeric strings based on given conditions
- Sum of indices of Characters removed to obtain an Empty String based on given conditions
- Construct the Cypher string based on the given conditions
- Decrypt a string according to given rules
- Decrypt the String according to given algorithm
- Encryption and Decryption of String according to given technique
- Rearrange a string according to the given indices
- Sort an array of strings according to string lengths
- Reverse String according to the number of words
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.