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.
- Sort an array of strings according to string lengths
- Print N-bit binary numbers having more 1’s than 0’s in all prefixes
- Find minimum shift for longest common prefix
- Prefixes with more a than b
- Python | Count all prefixes in given string with greatest frequency
- Check whether two strings can be made equal by increasing prefixes
- Sort an array of strings according to string lengths using Map
- Reduce the number to minimum multiple of 4 after removing the digits
- Check whether the given string is Palindrome using Stack
- Generate Binary Strings of length N using Branch and Bound
- Check if two strings can be made equal by swapping one character among each other
- Minimum operations required to make the string satisfy the given condition
- Find the most valued alphabet in the String
- Find the last two missing digits of the given phone number
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.