[ACCEPTED]-Topological Sort with Grouping-graph-theory

Accepted answer
Score: 11

Label all root nodes with a level value 8 0. Label all children with level value parent+1. If, a 7 node is being revisited i.e it already has 6 a level value assigned, check if the previously 5 assigned value is lower than the new one. If 4 so, update it with the higher value and 3 propagate them to the descendents.

now, you 2 have as many groups as there are unique 1 level labels 0 ... K

More Related questions