Given a string, you have to remove the three consecutive duplicates from the string. If no three are consecutive then output the string as it is.
Input : aabbbaccddddc Output :ccdc Input :aabbaccddc Output :aabbaccddc
We insert the characters of string one by one to vector and keep on checking the size of vector. If the size of vector is greater than 2, then we will check whether the last 3 characters of the string are same or not. If the characters are same
then we will move three steps backwards in array using resize() else not.
This article is contributed by Roshni Agarwal. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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.
- Remove all consecutive duplicates from the string
- Python groupby method to remove all consecutive duplicates
- Check if string is palindrome after removing all consecutive duplicates
- Remove duplicates from a given string
- Remove all duplicates from a given string in Python
- Remove duplicates from a string in O(1) extra space
- Remove duplicates from string keeping the order according to last occurrences
- Remove minimum characters from string to split it into three substrings under given constraints
- Generate a Binary String without any consecutive 0's and at most K consecutive 1's
- Recursively remove all adjacent duplicates
- Remove consecutive vowels from string
- 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 three or more consecutive identical characters or numbers
- Remove consecutive alphabets which are in same case
- Print all the duplicates in the input string
- Character replacement after removing duplicates from a string
- Print a closest string that does not contain adjacent duplicates
- Distinct permutations of a string containing duplicates using HashSet in Java
- Remove characters from the first string which are present in the second string