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:
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.
- Lower case to upper case - An interesting fact
- Convert camel case string to snake case in Java
- Convert Snake Case string to Camel Case in Java
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Count of character pairs at same distance as in English alphabets
- Find the length of the longest subsequence with first K alphabets having same frequency
- Longest substring of vowels with no two adjacent alphabets same
- Remove all characters other than alphabets from string
- Python | Toggle characters in words having same case
- Generate a Binary String without any consecutive 0's and at most K consecutive 1's
- Minimum number of deletions so that no two consecutive are same
- Minimum number of elements to be removed so that pairwise consecutive elements are same
- Check if a binary string contains consecutive same or not
- Group consecutive characters of same type in a string
- Length of the longest substring with no consecutive same letters
- Longest substring such that no three consecutive characters are same
- Minimum characters that are to be inserted such that no three consecutive characters are same
- Check if all bits can be made same by flipping two consecutive bits
- Minimum Cost of deletions such that string does not contains same consecutive characters
- Remove three consecutive duplicates from 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 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.