Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Implement a function to find the longest common subsequence between two strings.

Hard

Problem 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"));
Log in or sign up to run or submit your code.Log inSign up
Input
"abcdefg", "aceg"
Expected Output
aceg