Given a string S containing letters and digits, and an integer array Shift where, and for each element of Shift array . The task is, for each Shift[i] = X, you have to shift the first i+1 letters of S, X times. Return the final string after all applying all such shift to S.
Note : Shift means cyclically increment ASCII value.
Input: S = “abc789”, Shift = [2, 5, 9]
Explanation: Starting with “abc”.
After shifting the first 1 letters of S by 2, we have “cbc”.
After shifting the first 2 letters of S by 5, we have “hgc”.
After shifting the first 3 letters of S by 9, we have “qpl”.
Input : S = “geeksforgeeks”, Shift = [ 11, 10000, 9999999 ]
Output : qdnyulaufkuug
Approach: The i-th character of S is shifted Shift[i] + Shift[i+1] + … + Shift[Shift.length – 1] times.
So we update the Shift array backwards to know exact number of shifts to be applied to each element of string S.
Traverse the given text (S) one character at a time . For each character, transform the given character as per the rule, i:e apply shift, Shift[i] times . Return the new string generated.
Time Complexity: O(N), where N is the length of string S.
- Prefixes with more a than b
- Print N-bit binary numbers having more 1’s than 0’s in all prefixes
- Check whether two strings can be made equal by increasing prefixes
- Python | Count all prefixes in given string with greatest frequency
- Sort an array of strings according to string lengths
- Find minimum shift for longest common prefix
- Insert a Character in a Rotated String
- Convert a String to an Integer using Recursion
- Swap all occurrences of two characters to get lexicographically smallest string
- Longest subsequence with at least one character appearing in every string
- Number of balanced parenthesis substrings
- Append a digit in the end to make the number equal to the length of the remaining string
- Longest sub string of 0's in a binary string which is repeated K times
- Find the number of occurrences of a character upto preceding position
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.