Search⌘ K
AI Features

Solution: Sort Items by Groups Respecting Dependencies

Solution: Sort Items by Groups Respecting Dependencies asks you to arrange every item so each prerequisite comes first and items in each group stay together, or return an empty list if impossible.

Statement

You are given nn items indexed from 00 to n−1n − 1. Each item belongs to 00 or one of m groups, described by the array group, where:

  • group[i] ...