Loading
Loading
Two editors each took the same draft and deleted some characters from it, without adding or reordering anything. You only have their two results. A good estimate of how much of the draft survived both edits is the longest sequence of characters that appears, in order, in both results.
Return the length of the longest string that is a subsequence of both first and second. A subsequence keeps characters in their original order but may skip any of them.
first = "sunrise", second = "surprise"s = s, u = umatch both: length 2n has no partnerskip it in firstr = rlength 3; skip p and the second r in secondi, s, e match in orderlength 6: "surise"6Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(m × n) time · O(n) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
"surise" appears in order in both words.
Example 2
The two drafts share no characters.