In the beginning, you're given the list of modules and dependencies and each module is installed. So we start with A, B, C, D, E, F, G, Y, Z installed.
Then you go to remove A which is okay because nothing depends on A.
Then to remove A's dependencies (B and C) we can remove B because nothing depends on B, but we cannot remove C because G depends on C and G is installed.
Then we need to remove D and E because B depended on them.
D cannot be removed because G is installed and G depends on D.
E is removed since nothing depends on it (because B was already removed).
So we started with installed = [A, B, C, D, E, F, G, Y, Z]
And after removing A we get installed = [C, D, F, G, Y, Z]
So, for install A command, you need to install B and C too.
For install B, you need to install D and E. For install C, you need to install F as well.
For remove command - you need to remove given module and also all it's dependencies.
For example, remove A, you need to remove B. Here you can't remove C because C is a dependency of G.I think it's similar to https://leetcode.com/problems/reconstruct-itinerary/ but couldn't implement it in the end using Java. Any thoughts?
Happy coding!
Thanks.