Search⌘ K
AI Features

Solution: Sort Items by Groups Respecting Dependencies

Explore how to arrange items into grouped sequences that respect both inter-item and inter-group dependencies. Understand the construction of item-level and group-level dependency graphs and apply hierarchical topological sorting to achieve an order that maintains group continuity and prerequisite constraints, or determine when no valid ordering exists.

Statement

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

  • group[i] ...