PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of dynamic programming, string algorithms, and algorithmic problem-solving skills related to sequence comparison and the longest common subsequence concept.

  • medium
  • TikTok
  • Coding & Algorithms
  • Machine Learning Engineer

Find length of longest common subsequence

Company: TikTok

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given two strings `s` and `t`, return the **length** of their **longest common subsequence**. A subsequence is obtained by deleting zero or more characters without changing the relative order of the remaining characters. ### Input - `s`: string - `t`: string ### Output - Integer length of the longest common subsequence of `s` and `t`. ### Constraints (typical) - `0 <= len(s), len(t) <= 2000` - Strings consist of lowercase English letters (or ASCII characters). ### Example - `s = "abcde"`, `t = "ace"` → output `3` (one LCS is `"ace"`).

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.

Return the length of the longest common subsequence of two strings.

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

  1. Clarify edge cases before coding.
  2. Keep outputs deterministic when several valid answers exist.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)