Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Longest Common Subsequence

Medium

Topics
StringDynamic Programming

Given two strings text1 and text2, return the length of their longest common subsequence (characters in order, not necessarily contiguous). Return 0 if none.

Example 1

Input:  text1 = "abcde", text2 = "ace"
Output: 3

Example 2

Input:  text1 = "abc", text2 = "def"
Output: 0

Constraints

  • 1 <= text1.length, text2.length <= 1000
  • Inputs consist of lowercase English letters.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access