FunctionRacerProblemsRace

Shared Subsequence Length

MediumDynamic programmingPython, JavaScript, TypeScript, Java, C++

A subsequence of a string is what remains after deleting any number of its characters (possibly none) without reordering the rest. Return the length of the longest string that is a subsequence of both first and second. If the two strings share no character, or either one is empty, return 0.

Example 1

first "harbor"
second "arbiter"
returns 4

arbr can be read in order from both harbor and arbiter, and no longer string can.

Example 2

first "abc"
second "xyz"
returns 0

The strings share no character.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems