DIY: Sequence Reconstruction

Solve the interview question "Sequence Reconstruction" in this lesson.

Problem statement

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. Reconstruction means building a shortest common supersequence of the sequences in seqs (i.e., the 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.


The input will be a list of integers, org, and another list of lists of integers, seqs. The following is an example input:

org = [1,2,3]
seqs = [[1,2],[1,3],[2,3]]


The output will be a Boolean value representing whether org can be uniquely constructed from seqs. The following is just an example of what the output of the above input will look like:


[1,2],[1,3], and [2,3] are unique subsequences of org.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.