O55
Longest Common Subsequence
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) -> intInput & 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çerirExample 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: 0Example Test Scenarios (3)
Example 1: 'ace'
Input:
["abcde","ace"]Expected Output:
3Example 2: Birebir Eşit
Input:
["abc","abc"]Expected Output:
3Example 3: Ortak Karakter Yok
Input:
["abc","def"]Expected Output:
0