educative.io

Is this problem formulated correctly?

The explanation implies that the sequences given in the problem as an input, describe a DAG.
And it seems like the originalSeq is a path in the graph.
If that is correct than the fact that there are multiple correct topological sorts is not what defines the return value true/false.
The criteria that defines the output is the fact that this DAG has a given path or not.
In other words in a given DAG there is or there isn’t a path defined by the originalSeq.

Oddly enough the Example #2 fits the above (modified) problem statement. The false will be returned since there is no [1, 2, 3, 4] path in that DAG.
The graph for it is:

1 -> 2 -> 3
     |--> 4

Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Solution Review: Problem Challenge 1 - Grokking the Coding Interview: Patterns for Coding Questions


Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Solution Review: Problem Challenge 1 - Grokking the Coding Interview: Patterns for Coding Questions