O55

Longest Common Subsequence

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: NUMERIC

Problem Statement & Objective

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

Function Signature (Python)

longest_common_subsequence(text1: str, text2: str) -> int

Input & Output Contract

Output Rule:En uzun ortak alt dizinin uzunluğu tam sayısı.

System Constraints

1 <= metin1.length, metin2.length <= 1000
metin1 ve metin2 yalnızca küçük İngilizce harfler içerir

Example Execution Walkthrough

metin1 = 'abcde', metin2 = 'ace' -> 'ace' ortak ve uzunluğu 3 -> cevap: 3
metin1 = 'abc', metin2 = 'abc' -> cevap: 3
metin1 = 'abc', metin2 = 'def' -> ortak harf yok -> cevap: 0

Example Test Scenarios (3)

Example 1: 'ace'
Input:["abcde","ace"]
Expected Output:3
Example 2: Birebir Eşit
Input:["abc","abc"]
Expected Output:3
Example 3: Ortak Karakter Yok
Input:["abc","def"]
Expected Output:0
Loading Python Editor...
Input Parameters
[
  "abcde",
  "ace"
]
Expected Output
3