Topological ordering: There are n courses numbered 0 through n-1. Each [course, prerequisite] pair requires prerequisite first. Return whether all courses can be completed.
Input: A JSON object { "n": number, "prerequisites": [number, number][] }.
Output: A JSON boolean that is false exactly when the dependency graph contains a cycle.
Constraints:
- 0 <= n <= 100000
- Every course id is in 0..n-1
- Repeated prerequisite pairs are allowed
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: EASY. Variant: 19. Expect follow-up questions about complexity, edge cases, and alternative approaches.
Practice context
This coding (algo) exercise trains prompt interpretation, explicit assumptions, a concrete response, and a concise explanation of the decisions made. It is marked easy difficulty.
The signed-in workspace prov