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
gnanagowthaman sankarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

krakatoaCommented:
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

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.