All tasks
Harddpstrings

Longest Common Subsequence

Time limit 2 s · Memory 64 MBAcceptance: —Solved by: 0

Statement

Two lines contain two strings of lowercase Latin letters. Print the length of their longest common subsequence. A subsequence is obtained by deleting some characters of a string while keeping the order of the rest.

Examples

Example 1
Input
abcde
ace
Output
3
Example 2
Input
abc
def
Output
0

Constraints

  • Each string has length between 1 and 2000
Solve this task to unlock the editorial.

AI tutor

Stuck? Get a nudge — the tutor explains the idea, it never hands you the solution.