Build a graph from given subsequences. Select each sub-sequence one by one and add an edge between two adjacent elements in the sub-sequence. After building the graph, perform topological sorting on the graph.
Refer topological sorting for understanding topological sort. This topological ordering is the required array.
Build original array from the given sub-sequences : https://www.geeksforgeeks.org/build-original-array-from-the-given-sub-sequences/