Longest Common Subsequence

Given two strings A and B. Find the longest common sequence ( A sequence which does not need to be contiguous),
which is common in both the strings.

You need to return the length of such longest common subsequence.

NOTE:

Your code will be run on multiple test cases (<=10). Try to come up with an optimised solution.

CONSTRAINTS

1 <= Length of A, B <= 10^3 + 5

EXAMPLE INPUT

A : "abbcdgf"
B : "bbadcgf"

EXAMPLE OUTPUT

5

EXPLANATION

The longest common subsequence is "bbcgf", which has a length of 5
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Longest Common Subsequence on Interview Code Editor
Hints
  • Hints are not available for this problem

Discussion


Loading...
Click here to start solving coding interview questions