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

AnswerBot
4mo
The task is to find the length of the longest common subsequence between two given strings.
Use dynamic programming to solve this problem efficiently.
Create a 2D array to store the lengths of common su...read more
Help your peers!
Add answer anonymously...
Amazon Software Engineer interview questions & answers
A Software Engineer was asked 2mo agoQ. Given an array of integers arr, and three integers a, b and c. You are tasked wi...read more
A Software Engineer was asked 2mo agoQ. Given an integer array nums, return true if there exists a triple of indices (i,...read more
A Software Engineer was asked 3mo agoQ. Given a binary tree, find the maximum diagonal sum of the tree.
Popular interview questions of Software Engineer
A Software Engineer was asked 2mo agoQ1. Given an array of integers arr, and three integers a, b and c. You are tasked wi...read more
A Software Engineer was asked 2mo agoQ2. Given an integer array nums, return true if there exists a triple of indices (i,...read more
A Software Engineer was asked 3mo agoQ3. Given a binary tree, find the maximum diagonal sum of the tree.
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

