Jayant-001 / Hacktoberfest2023

Contribute here to take part in Hacktoberfest2023
https://hacktoberfest.com
1 stars 16 forks source link

Create Longest_common_sequence.cpp #21

Closed meenuarora456123 closed 1 year ago

meenuarora456123 commented 2 years ago

Given two strings s1 and s2, return the length of their longest common subsequence. If there is no common subsequence, return 0.

A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

For example, "ace" is a subsequence of "abcde". A common subsequence of two strings is a subsequence that is common to both strings.

Example :

Input : s1 = "ABCDGH", s2 = "AEDFHR"
Output: 3
Explanation : "ADH" is the LCS between s1 and s2

Input : s1 = "AGGTAB", s2 = "GXTXAYB"
Output: 4
Explanation : “GTAB” is the LCS between s1 and s2

Input : s1 = "ABCHG", s2 = "ABGCF"
Output: 3
Explanation : "ABC" & "ABG" is the LCS between s1 and s2