LeetCode 1203 Sort Items by Groups Respecting Dependencies - Why Naive Fails

The trap

Do a single topological sort considering all dependencies.

This doesn't guarantee items in the same group stay together. Items from different groups might interleave.

You need to sort both items within groups AND groups relative to each other.