Given a string str, the task is to repeat every substring of the string X number of times where X is the number composed of the consecutive digits present just after the substring in the original string. For example, if str = “g1e2ks1” then the resultant string will be “geeks”.
Input: str = “2a10bd3”
First digit “2” is unnecessary as there is no valid substring before it.
“a” will be repeated 10 times and then “bd” will be repeated thrice.
Input: str = “g1ee1ks1for1g1e2ks1”
Approach: Find the first valid substring i.e. the substring which doesn’t contain any digit then parse the integer present just after the found substring using parseInt() and then repeat the found substring the required number of times. Repeat these steps for all valid substrings and then print the resultant string.
Below is the implementation of the above approach:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Number of substrings of a string
- Sum of all substrings of a string representing a number | Set 1
- Number of substrings of one string present in other
- Number of even substrings in a string of digits
- Number of substrings divisible by 6 in a string of integers
- Number of substrings with odd decimal value in a binary string
- Minimum number of given operations required to convert a string to another string
- Rearrange the string to maximize the number of palindromic substrings
- Count number of substrings of a string consisting of same characters
- Given a binary string, count number of substrings that start and end with 1.
- Count the number of vowels occurring in all the substrings of given string
- Split the binary string into substrings with equal number of 0s and 1s
- Count of substrings which contains a given character K times
- Minimum number of substrings the given string can be splitted into that satisfy the given conditions
- Sum of all substrings of a string representing a number | Set 2 (Constant Extra Space)
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.
Improved By : sanjeev2552