Can Subsequences Share One Master Sequence?
Problem statement
Each row of subsequences lists distinct tokens in the order in which they must appear.
Decide whether there exists one master sequence that contains every distinct token exactly once and has every row as a subsequence.
Return true when such a master sequence exists, otherwise return false. You do not need to construct the master sequence.
Function
canShareMasterSequence(subsequences: String[][]) → booleanExamples
Example 1
subsequences = [["a","b"],["a","c"]]return = trueBoth rows are subsequences of [a,b,c].
Example 2
subsequences = [["a","b"],["b","a"]]return = falseThe first row requires a before b, while the second requires the reverse.
Example 3
subsequences = [["a","c"],["a","b","c"],["b","d"]]return = true[a,b,c,d] respects every reported order constraint.
Constraints
1 <= subsequences.length <= 100000.- Every row contains from
1through100000distinct tokens. - The total number of token occurrences is at most
200000. - Every token is a non-empty lowercase English string of length at most
30.