Description

Given a sequence org and a list of sequences, check if org is the unique shortest supersequence that can be reconstructed from the sequences.

Examples

Input:org = [1,2,3], seqs = [[1,2],[1,3]]
Output:false
Explanation:

Not unique.

Input:org = [1,2,3], seqs = [[1,2],[1,3],[2,3]]
Output:true
Explanation:

For org = [1,2,3], seqs = [[1,2],[1,3],[2,3]], the answer is true because the sequence reconstruction condition is satisfied.

Input:org = [4,1,5,2,6,3], seqs = [[5,2,6],[4,1,5],[1,5,2],[2,6,3]]
Output:true
Explanation:

The sequences provide enough ordering constraints to uniquely reconstruct the original sequence. From the sequences, it is possible to deduce: 4→1→5→2→6→3, which matches the original exactly.

Constraints

  • 1 ≤ org.length ≤ 10⁴

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!