Python data engineering interview problem. Difficulty: advanced. Pattern: Graphs. About 18 minutes. Part of the Pro drill bank.
Whether all courses can be finished given prerequisites. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement can_finish(num_courses: int, prerequisites: list) -> bool. prerequisites entries are [course, prereq] meaning prereq → course. ; 2, [[1, 0], [0, 1]] → False.
Input: can_finish(2, [[1, 0]]) Output: True Linear order 0 then 1.
Topics: lakebench, python, topo, cycle.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Whether all courses can be finished given prerequisites.
Implement `can_finish(num_courses: int, prerequisites: list) -> bool`. prerequisites entries are `[course, prereq]` meaning prereq → course. Example: `2, [[1, 0]]` → `True`; `2, [[1, 0], [0, 1]]` → `False`. Keep the harness.