Longest Common Subsequence Problem Statement

Given two strings, S and T with respective lengths M and N, your task is to determine the length of their longest common subsequence.

A subsequence is a sequence that appears in the same relative order, but not necessarily contiguous. For example, in the string "abc", the subsequences include "", "a", "b", "c", "ab", "bc", "ac", "abc", among others.

Input:

The first line contains the string 'S' of length 'M'.
The second line contains the string 'T' of length 'N'.

Output:

Return the length of the Longest Common Subsequence as an integer.

Example:

Input:
S = "abcde"
T = "ace"
Output:
3
Explanation:

The Longest Common Subsequence is "ace".

Constraints:

  • 0 ≤ M ≤ 103
  • 0 ≤ N ≤ 103
  • Time Limit: 1 second
Be the first one to answer
Add answer anonymously...
Amazon Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter