# Can Anyone help me. Please explain the question i cant get it and logic behind it.

Recursion

Given a string and a non-empty substring sub, compute recursively the largest substring which starts and ends with sub and return its length.

strDist("catcowcat", "cat") → 9
strDist("catcowcat", "cow") → 3
strDist("cccatcowcatxx", "cat") → 9
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
You need to look for the given substring (('sub'), the second argument of the two), somewhere inside the first-given string, ('string'), and ensure that 'sub' both starts and  ends some substring in the first argument, 'string'.

So in the first example, cat begins and ends catcowcat, and the length of the string catcowcat is 9. However, if there were another 'string' such as catcowcatdogcatcowcowcowcat, then you would be returning an int of length 15, since catcowcowcowcat is longer than catcowcat. You need to code for that in the search algorithm.

The third example is the same as that, but the second example wants you to return 3, because cow both starts and ends cow in 'string'.

As for the recursive nature of the question, you can adapt the method that I showed in your previous question on recursion.
0

Experts Exchange Solution brought to you by