Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

text1 =
text2 =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Classic 2D DP on prefixes.

Approach

dp[i][j] = LCS length of text1[:i] and text2[:j]. If chars equal: dp[i-1][j-1] + 1, else max(dp[i-1][j], dp[i][j-1]). Use 1D rolling array.

Code
Loading...
Complexity
Time: O(mn)
Space: O(min(m,n))
Solution
Updated: 2026-02-23

Idea

Classic 2D DP on prefixes.

Approach

dp[i][j] = LCS length of text1[:i] and text2[:j]. If chars equal: dp[i-1][j-1] + 1, else max(dp[i-1][j], dp[i][j-1]). Use 1D rolling array.

Code
Loading...
Complexity
Time: O(mn)
Space: O(min(m,n))