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