Participate in Codex, Test Your Skills & Win BIG

Longest Common Subsequence

Problem Description

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.

Problem Constraints

1 <= |A|, |B| <= 1005

Input Format

First argument is an string A.

Second argument is an string B.

Output Format

Return the length of such longest common subsequence between string A and string B.

Example Input

Input 1:

 A = "abbcdgf"
 B = "bbadcgf"

Example Output

Output 1:


Example Explanation

Explanation 1:

 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
  • Hint 1
  • Solution Approach
  • Complete Solution
Asked In:


Click here to start solving coding interview questions