Please enter your email address or userHandle.
Given two sequences, find the length of longest subsequence present in both of them. Both the strings are of uppercase.
A = 6, B = 6
str1 = ABCDGH
str2 = AEDFHR
Explanation: LCS for input Sequences
“ABCDGH” and “AEDFHR” is “ADH” of
A = 3, B = 2
str1 = ABC
str2 = AC
Explanation: LCS of "ABC" and "AC" is
"AC" of length 2.
Complete the function lcs() which takes the length of two strings respectively and two strings as input parameters and returns the length of the longest subsequence present in both of them.
Expected Time Complexity : O(|str1|*|str2|)
Expected Auxiliary Space: O(|str1|*|str2|)
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
want to view the editorial?
Login to access your submissions.