Given a string str, the task is to remove consecutive characters from the string that are in same case (Uppercase or Lowercase) and print the resultant string.
Input: str = “GeeksForGeeks”
Input: str = “abcDEFghi”
- Print the first character as it is.
- Traverse through all the other characters in the string starting from second character.
- Compare the current and the previous characters:
- If the current and the previous characters are in the same case then skip.
- Else print the current character.
Below is the implementation of the above approach:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Remove all characters other than alphabets from string
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Remove three consecutive duplicates from string
- Remove consecutive vowels from string
- Remove all consecutive duplicates from the string
- Python groupby method to remove all consecutive duplicates
- Lower case to upper case - An interesting fact
- Count of alphabets having ASCII value less than and greater than k
- Print the Alphabets A to Z in Star Pattern
- Program to generate random alphabets
- Generate a string with maximum possible alphabets with odd frequencies
- Maximum distinct lowercase alphabets between two uppercase
- Sub-string that contains all lowercase alphabets after performing the given operation
- Count and Print the alphabets having ASCII value in the range [l, r]
- Count and Print the alphabets having ASCII value not in the range [l, r]
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.