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
- Given a string and an integer k, find the kth sub-string when all the sub-strings are sorted according to the given condition
- Print array of strings in sorted order without copying one string into another
- Rearrange given string to maximize the occurrence of string t
- Rearrange a string so that all same characters become d distance away
- Rearrange characters in a string such that no two adjacent are same
- Check if words are sorted according to new order of alphabets
- Print all permutations in sorted (lexicographic) order
- Rearrange characters in a string such that no two adjacent are same using hashing
- Rearrange a string so that all same characters become atleast d distance away
- 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
- Find alphabetical order such that words can be considered sorted
- Rearrange the string to maximize the number of palindromic substrings
- Rearrange the given string such that all prime multiple indexes have same character