Implement a function to find the longest common subsequence between two strings.
HardProblem Statement
Implement a function to find the longest common subsequence between two strings.
Sample Input
"abcdefg", "aceg"
Sample Output
aceg
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
// Find the longest common subsequence between two strings
function longestCommonSubsequence(str1, str2) {
// Initialize a 2D array for dynamic programming
// Loop through both strings, comparing characters and updating the 2D array
// Return the constructed longest common subsequence
}
console.log(longestCommonSubsequence("abcdefg", "aceg"));
Input
"abcdefg", "aceg"
Expected Output
aceg