Given a string str consisting of upper case alphabets, numeric digits and arithmetic operators, the task is to group them into continuous sub-strings of same type.
Input: str = “G E E K S 1 2 3 4 5”
Output: GEEKS 12345
All contiguous upper case characters can be grouped together
and all the numeric characters can be grouped together in a separate group.
Input: str = “DEGFT +- * 5 6 7”
Output: DEGFT +-* 567
Approach: Remove all the spaces from string. After removing all the white spaces, traverse the string one by one and group the characters according to their ASCII values.
Below is the implementation of the above approach:
34 FTG 234 ++-*
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Minimum Cost of deletions such that string does not contains same consecutive characters
- Reduce the string by removing K consecutive identical characters
- Binary string with given frequencies of sums of consecutive pairs of characters
- Strings formed from given characters without any consecutive repeating characters
- Minimum characters that are to be inserted such that no three consecutive characters are same
- Group words with same set of characters
- Group all occurrences of characters according to first appearance
- Count of ungrouped characters after dividing a string into K groups of distinct characters
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Longest substring such that no three consecutive characters are same
- Print consecutive characters together in a line
- Check three or more consecutive identical characters or numbers
- Length of the longest substring with consecutive characters
- Min flips of continuous characters to make all characters same in a string
- Minimum swaps to group similar characters side by side?
- Group Shifted String
- String with k distinct characters and no same characters adjacent
- Minimum jumps required to group all 1s together in a given Binary string
- Lexicographically smallest string formed by appending a character from the first K characters of a given 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.