0444. Sequence Reconstruction
https://leetcode.com/problems/sequence-reconstruction
Description
Check whether the original sequence org
can be uniquely reconstructed from the sequences in seqs
. The org
sequence is a permutation of the integers from 1 to n, with 1 ≤ n ≤ 104. Reconstruction means building a shortest common supersequence of the sequences in seqs
(i.e., a shortest sequence so that all sequences in seqs
are subsequences of it). Determine whether there is only one sequence that can be reconstructed from seqs
and it is the org
sequence.
Example 1:
Example 2:
Example 3:
Example 4:
Constraints:
1 <= n <= 10^4
org
is a permutation of {1,2,...,n}.1 <= segs[i].length <= 10^5
seqs[i][j]
fits in a 32-bit signed integer.
UPDATE (2017/1/8): The seqs parameter had been changed to a list of list of strings (instead of a 2d array of strings). Please reload the code definition to get the latest changes.
ac
Last updated