| Topic | Difficulty | Companies |
|---|---|---|
| Dynamic Programming | MEDIUM | Amazon Google |
Given two strings X and Y, write a program to return the length of their longest common subsequence.
Problem Note
Example 1
Input: X = "pqrst", Y = "prt"
Output: 3
Explanation: The longest common subsequence is "prt" and its length is 3.
Example 2
Input: X = "pqr", Y = "pqr"
Output: 3
Explanation: The longest common subsequence is "pqr" and its length is 3.
Example 3
Input: X = "pqr", Y = "stu"
Output: 0
Explanation: There is no such common subsequence, so the result is 0.