Skip to main content
Medium Topological Sort Low frequency

Sequence Reconstruction

Approach Summary

Build a graph from the sequences. In topological sort, if the queue ever holds > 1 candidate, the order is not unique.

How to Recognize This Pattern

  • "Is org the only shortest supersequence of all seqs"
  • Uniqueness = queue never has more than one element at a time

Complexity Analysis

Time Complexity

O(V + E)

Space Complexity

O(V + E)

Tags

Array Graph Topological Sort BFS

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee