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.
- Print all the duplicates in the input string
- Remove characters from the first string which are present in the second string
- Print reverse of a string using recursion
- Write a program to print all permutations of a given string
- Print list items containing all characters of a given word
- Find the smallest window in a string containing all characters of another string
- Length of the longest substring without repeating characters
- Print all permutations with repetition of characters
- Print all interleavings of given two strings
- Interleaving of two given strings with no common characters
- Print all permutations in sorted (lexicographic) order
- Given a sequence of words, print all anagrams together | Set 1
- Given a sequence of words, print all anagrams together | Set 2
- String matching where one string contains wildcard characters
- Find the first non-repeating character from a stream of characters