Medium · Strings

Shortest Way to Form String

Given ASCII 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

Open every published interview problem, solution, scene, and memory room free, with no account.

More Strings problems