Sponsored
Use these hints if you're stuck. Try solving on your own first.
Think of it as a graph problem.
We need to find a topological order on the dependency graph.
Build two graphs, one for the groups and another for the items.
Solve with full IDE support and test cases