Given three strings a, b and c. Trying to check whether c is an interspersed version of a and b, recursively.
So an example would be.
a = dolphin
b = whale
c = dolwhphialne
You can see that the chars in the c string are in the same order as they would be in their original strings, just shuffled up a little bit.
The algorithm I'm working on is.
Algorithm: stringOrderedCheck(a,b,c)
n:= length of a
m:= length of b
nm:= length of a and b
if (nm > 0) then
if(first letter of a equals first letter of c) then
return stringOrderedCheck(a without first letter,b, c without first letter)
else if(first letter of b equals first letter of c) then
return stringOrderedCheck(a,b without first letter, c without first letter)
else
return false;
But the problem that I am getting is this for example:
a = yyyyb
b = yyyx
c = yyyyxyyyb
How do I prepare the function to realise that it needs to take the first letter from a which is y then take the next 4 from b which is yyyx.
Duplicate values are causing me a major issue.
I need to do something when both chars in a and b equal the char in c
length of a and bWhat are you calculating here? The sum? The minimum?