Longest Common Subsequence

Medium · 2-D Dynamic Programming · String · Dynamic Programming

Problem

Return the length of the longest subsequence common to both text1 and text2.

A subsequence keeps the original order but may skip characters; it need not be contiguous.

Examples

Input: text1 = "abcde", text2 = "ace"
Output: 3

"ace" appears in order in both.

Input: text1 = "abc", text2 = "abc"
Output: 3
Input: text1 = "abc", text2 = "def"
Output: 0

Nothing in common.

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…