Given a string str consisting of lowercase English alphabets. The task is to add all the character values i.e. ‘a’ = 1, ‘b’ = 2, ‘c’ = 3, …, ‘z’ = 26 and output the character corresponding to the sum value. If it exceeds 26 then take sum % 26.
Input: str = “gfg”
(g + f + g) = 7 + 6 + 7 = 20 and t = 20
Input: str = “geeks”
- Find the sum of all character of the string and store it in a variable sum.
- If sum % 26 = 0 then print ‘z’.
- Else update sum = sum % 26 and print (sum + ‘a’ + 1).
Below is the implementation of the above 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.
- Check if a two character string can be made using given words
- Check if a given string is made up of two alternating characters
- Check if permutation of a given string can be made palindromic by removing at most K characters
- Check whether the number can be made perfect square after adding 1
- N-th character in the string made by concatenating natural numbers
- Minimal moves to form a string by adding characters or appending string itself
- Check if all strings of an array can be made same by interchanging characters
- Replace all occurrences of character X with character Y in given string
- Check if a string is made up of K alternating characters
- Minimum operations required to convert all characters of a String to a given Character
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Find the starting indices of the substrings in string (S) which is made by concatenating all words from a list(L)
- Map every character of one string to another such that all occurrences are mapped to the same character
- Check if two strings can be made equal by swapping one character among each other
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Find a string such that every character is lexicographically greater than its immediate next character
- Check whether two strings can be made equal by copying their characters with the adjacent ones
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Minimum number of operations to move all uppercase characters before all lower case characters
- Min flips of continuous characters to make all characters same in a string
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.