Given a string containing uppercase alphabets and integer digits (from 0 to 9), the task is to print the alphabets in the order followed by the sum of digits.
Input : AC2BEW3 Output : ABCEW5 Alphabets in the lexicographic order followed by the sum of integers(2 and 3).
Implementation: 1- Start traversing the given string. a) If an alphabet comes increment its occurrence count into a hash_table. b) If an integer comes then store it separately by summing up everytime. 2- Using hash_table append all the characters first into a string and then at the end, append the integers sum. 3- Return the resultant string.
Time Complexity: O(n)
This article is contributed by Sahil Chhabra. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Rearrange a string in the form of integer sum followed by the minimized character
- Print array of strings in sorted order without copying one string into another
- Rearrange a string so that all same characters become d distance away
- Rearrange characters in a string such that no two adjacent are same
- Rearrange a binary string as alternate x and y occurrences
- Check if it is possible to rearrange a binary string with alternate 0s and 1s
- Rearrange a string so that all same characters become atleast d distance away
- Check if words are sorted according to new order of alphabets
- Print all permutations in sorted (lexicographic) order
- Rearrange the string to maximize the number of palindromic substrings
- Find alphabetical order such that words can be considered sorted
- Given a sorted dictionary of an alien language, find order of characters
- Find the count of palindromic sub-string of a string in its sorted form
- Sort a string according to the order defined by another string
- Convert a String to Integer Array in C/C++