Course Schedule With Retries
Courses arrive as objects { id, prerequisites }, and an external function didFail(id) reports whether an attempt at a course failed. Schedule attempts with a queue: start with every course that has no prerequisites, in input order; take the front course and attempt it; if it fails, push it to the back of the queue; if it passes, push (in input order) every course not yet queued or passed whose prerequisites have all passed. Return the list of attempted ids in order. Courses that can never become ready are simply never attempted.
courses = [{ id: "A", prerequisites: [] }, { id: "B", prerequisites: ["A"] }, { id: "C", prerequisites: ["A"] }]
didFail fails "A" once -> ["A", "A", "B", "C"]Hints
Hint 1
Keep three sets: queued, passed, and the queue itself. Only a pass can unlock dependants, so the unlock scan runs after a pass, over the courses in input order.
Hint 2
Re-queueing a failed course at the back is the whole retry rule; no other state changes on a failure.