BugForge
DSA

Common Shopping Pattern

Mediumdynamic programming2D DP 00:00

Two customers' click histories are strings. Return the length of their longest common subsequence.

Signature

lcs(a: string, b: string) → int
Example 1
a = "abcde"
b = "ace"
output = 3
'ace' → 3
Example 2
a = "abc"
b = "def"
output = 0
0

Constraints

  • 1 ≤ |a|, |b| ≤ 1000
Run checks the examples. Submit runs every hidden test (17, including large inputs that catch slow solutions).