Given a sequence of characters, print consecutive sequence of characters in a line, otherwise
print it in a new line.
Input : ABCXYZACCD Output : ABC XYZ A C CD Input : ABCZYXACCD Output: ABC ZYX A C CD
The idea is to traverse string from left to right. For every traversed character, print it in a line if it is consecutive to previous one, else print a new line character.
ABC XYZ A C CD
Time Complexity : O(n)
This article is contributed by Rakesh Kumar. 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.
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
- 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
- Longest substring such that no three consecutive characters are same
- Group consecutive characters of same type in a string
- Check three or more consecutive identical characters or numbers
- 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
- Print all permutations with repetition of characters
- Print Longest substring without repeating characters
- Print all valid words that are possible using Characters of Array
- Print characters in decreasing order of frequency
- Print characters having odd frequencies in order of occurrence
- Print characters having even frequencies in order of occurrence
- Print characters and their frequencies in order of occurrence
- Print list items containing all characters of a given word
- Print common characters of two Strings in alphabetical order
- Print all distinct characters of a string in order (3 Methods)
- Print characters having prime frequencies in order of occurrence