Topological sort interview question! Help needed!

You have a build service to use, which will get all the dependent libraries.
List dependentLibs = buildservice.getDependents("a"); // gives b,c,d,e
a-> b,c,d,e
b-> c,d
c -> d
d -> {}
e -> {}

I know that it is a topological sorting question.
I said that i can map
b->a
c->a,b
d->a,b,c
e->a

and also calculated the indegree for all of all them and did it.
Follow up was not to store the above mappings, lets say there are some libraries which are very frequent and that will consume a lot of space. How to approach this question?

Comments (2)