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
- C Program to concatenate two strings without using strcat
- Print characters in decreasing order of frequency
- Minimum number of additons to make the string balanced
- Extract all integers from the given string in Java
- Minimum number of substrings the given string can be splitted into that satisfy the given conditions
- Minimum length String with Sum of the alphabetical values of the characters equal to N
- C program to print the length of a String using %n format specifier
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.