logo CodeStepByStep logo

You are working on problem set: Week 4 Section ( Pause)

longestCommonSubsequence

Language/Type: C++ recursion backtracking string
Related Links:

Write a recursive function named longestCommonSubsequence that returns the longest common subsequence of two strings. Recall that if a string is a subsequence of another, each of its letters occurs in the longer string in the same order, but not necessarily consecutively. For example, the following calls should return the following values:

Call Return
longestCommonSubsequence("marty", "megan") "ma"
longestCommonSubsequence("hannah", "banana") "anna"
longestCommonSubsequence("she sells", "seashells") "sesells"
longestCommonSubsequence("janet", "cs106b") ""

Do not use any loops. Your function must be recursive.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? .

If something seems wrong with our site, please

Is there a problem? Contact us.