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.

Input

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]]

Output

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:

True

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

Coding exercise

Implement the function sequence_reconstruction(org, seqs), where org is the list and seqs is the list of lists. The function will return a Boolean value representing whether org can be uniquely constructed from seqs.

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