Find length of longest common subsequence
Company: TikTok
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of dynamic programming, string algorithms, and algorithmic problem-solving skills related to sequence comparison and the longest common subsequence concept.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ('abcde','ace')
Expected Output: 3
Explanation: ace is a common subsequence.
Input: ('abc','abc')
Expected Output: 3
Explanation: Identical strings have full LCS length.
Input: ('abc','def')
Expected Output: 0
Explanation: No shared characters gives zero.
Input: ('', 'abc')
Expected Output: 0
Explanation: Empty string has LCS length zero.
Hints
- Clarify edge cases before coding.
- Keep outputs deterministic when several valid answers exist.