Problem
You get two strings text1 and text2. Return the length of their longest common subsequence. If the strings have no common subsequence, return 0.
A subsequence of a string is a string that you get when you remove zero or more characters. The remaining characters keep their order.
A common subsequence is a subsequence of both strings.
Example 1
- Input:
- text1 = "kitchen", text2 = "thicken"
- Output:
- 4
- Explanation:
- One longest common subsequence is
"then".
Example 2
- Input:
- text1 = "mango", text2 = "among"
- Output:
- 3
- Explanation:
- Both
"ang"and"mng"are common subsequences with the length 3.
Example 3
- Input:
- text1 = "abc", text2 = "xyz"
- Output:
- 0
- Explanation:
- The two strings have no character in common.
Constraints
- 1 <= text1.length, text2.length <= 1000
- text1 and text2 have only lowercase English letters.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Longest Palindromic Subsequence
Coding · Dynamic Programming · String
- Longest Palindromic Substring
Coding · Dynamic Programming · Manacher · String
- Longest Valid Parentheses
Coding · Bracket Sequences · Dynamic Programming · Stack
- Decode Ways
Coding · Dynamic Programming · String
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 1143. Longest Common Subsequence
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 2 records
Apple
Longest Common Subsequence
Reported date not specified · Source window: 3mo
Source snapshot: Oct 20, 2026
Source frequency score: 71. This is not an interview probability.
View sourceApple
Longest Common Subsequence
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 68.6. This is not an interview probability.
View source