← problems
#1143

Longest Common Subsequence

MediumDynamic Programming

Given two strings text1 and text2, return the length of their longest common subsequence. If there is none, return 0.

A subsequence keeps relative order but need not be contiguous.

Example

text1 = "abcde", text2 = "ace"  => 3   // "ace"
text1 = "abc", text2 = "def"    => 0
Implement
function LongestCommonSubsequence(text1: string, text2: string) -> int

Found a bug? Or annoyed about something in the language? Tell us.

loading editor…