educative.io

Wouldn't this 5, 6, 4, 3, 2, 1, 0 be also a correct order?

There are following answers given as correct ones:

1) 5, 6, 3, 4, 0, 1, 2
2) 6, 5, 3, 4, 0, 1, 2
3) 5, 6, 4, 3, 0, 2, 1
4) 6, 5, 4, 3, 0, 1, 2
5) 5, 6, 3, 4, 0, 2, 1
6) 5, 6, 3, 4, 1, 2, 0

but it appears from the graph picture that the 5, 6, 4, 3, 2, 1, 0 should also be a correct order, no?


Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Topological Sort (medium) - Grokking the Coding Interview: Patterns for Coding Questions

Hi @Peter_Litvak,

Yes, just as is mentioned in example 3, there are other valid topological ordering of the graph too. This one is a valid order.