Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Longest Common Subsequence solution to C++ folder #74

Merged
merged 2 commits into from
Oct 31, 2024

Conversation

anaghapuv
Copy link
Contributor

Problem Statement: Given two strings text1 and text2, 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.

Solution: To find the longest common subsequence in two strings :
We first make a dynamic programming table c, using a 2D array.
The first row and first column are initialized to zero.
If characters match the LCS increases by 1 (we increment the value of [i-1][j-1].
Otherwise, it takes the maximum LCS length and skips the character.
The final length is stored in c and that is what is returned.

Output:
Test Case 1: text1 = "abcde"; text2 = "ace": Output: 3
Test Case 2: text1 = "abc"; text2 = "abc": Output: 3
Test Case 3: text1 = "abc"; text2 = "def": Output: 0

I would really appreciate it if you accept this pull request and assign it under the appropriate Hacktoberfest 2024 tags before merging.
Thankyou!

@abhisek247767
Copy link
Owner

here two files there

@abhisek247767 abhisek247767 added enhancement New feature or request question Further information is requested and removed Hacktoberfest-Accepted Hacktoberfest-2024 labels Oct 16, 2024
@anaghapuv
Copy link
Contributor Author

Oh, I am so sorry, I added the full form later on to avoid confusion

@anaghapuv
Copy link
Contributor Author

Do i delete this and submit another pull request?

@abhisek247767
Copy link
Owner

Sure or if you wish do it here also

@abhisek247767 abhisek247767 added good first issue Good for newcomers Hacktoberfest-Accepted Hacktoberfest-2024 and removed enhancement New feature or request question Further information is requested labels Oct 31, 2024
@abhisek247767 abhisek247767 merged commit c4f99fc into abhisek247767:main Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants