Shortest Sequence of Source Subsequences
Problem statement
Form target by concatenating subsequences of source. Return the minimum number of source subsequences required, or -1 when impossible. An empty target requires zero subsequences.
Function
shortestSourceSubsequences(source: String, target: String) → intExamples
Example 1
source = "abc"target = "abcbc"return = 2Use abc followed by bc.
Example 2
source = "abc"target = "acdbc"return = -1The character d never occurs in source.
Example 3
source = "xyz"target = ""return = 0No subsequence is needed.
Constraints
1 <= source.length <= 10^5.0 <= target.length <= 10^5.- Both strings contain lowercase English letters.