![]() |
VOOZH | about |
Given a sequence of characters, print consecutive sequence of characters in a line, otherwise
print it in a new line.
Examples:
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.
Implementation:
ABC XYZ A C CD
Time Complexity: O(n)
Auxiliary Space: O(1)