Your question is Topological Sort DSA. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Speechify Reader may need to assemble a document from segments such as a title, headings, paragraphs, and footnotes. Some segments must be played before others. Given the segment identifiers and precedence constraints, return a valid playback order.
If multiple segments are currently available, choose the lexicographically smallest identifier. This makes the result deterministic. If the constraints contain a cycle, return an empty list because no valid playback order exists.
Implement schedule_playback(items, prerequisites), where items is a list of unique strings and prerequisites is a list of pairs [before, after], meaning before must appear earlier than after. Return a list containing every item exactly once, or [] when no valid ordering exists.
def schedule_playback(items, prerequisites):