Medium · Strings

Shortest Way to Form String

Given strings source and target, return the minimum number of subsequences of source whose concatenation equals target, or -1 if target cannot be formed.

Examples

Example 1

{
  "source": "abc",
  "target": "abcbc"
}

Output: 2 subsequences

Example 2

{
  "source": "xyz",
  "target": "xzyxz"
}

Output: 3 subsequences

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Strings problems