In one of my recent interviews I was given a question as follows -
Divide the string into substrings with repeating characters, such that
Example 1
Input : ababccdecfg
Output : [abab, ccdec, f, g]
Example 2
Input : bbbb
Output : [bbbb]
Example 3
Input : abcd
Output : [a, b, c, d]
Signature of the function was
std::vector<std::string> Split(std::string str)
{ //write code here }
Initially, I tried to approach it using sliding window and then using recursion. The more I thought about it, it got more complicated and I eventually gave up.
I am looking for suggestions on how to approach it. Any help is appreciated. Thank you.