Course Schedule
Real-world version: Apprenticeship Skill PlanThe statement here is our own: the same inputs, outputs and technique.
A trade academy signs off apprentices on skillCount skills, labelled 0 through skillCount - 1. An apprentice attempts one skill at a time and must respect the academy's gating rules.
You are given requirements, where requirements[i] = [skill, gate] means the assessor will not let anyone attempt skill until gate has already been signed off. A skill that gates itself can therefore never be attempted. Only feasibility matters here — you are not asked which order to use.
Return true when at least one attempt order signs off the whole catalogue, and false when no order does.
Examples
Example 1
- Input
- skillCount = 4, requirements = [[1, 0], [2, 0], [3, 1], [3, 2]]
- Output
- true
Skill 0 opens both skill 1 and skill 2, and once those two are signed off skill 3 becomes available, so the whole catalogue clears.
Example 2
- Input
- skillCount = 2, requirements = [[0, 1], [1, 0]]
- Output
- false
Each of the two skills gates the other, so neither can ever be the first attempt.
Example 3
- Input
- skillCount = 6, requirements = [[1, 0], [3, 2], [5, 4]]
- Output
- true
The catalogue splits into three unrelated pairs, and each pair is cleared by taking the gate before the skill it guards.
Constraints
- 1 <= skillCount <= 2000
- 0 <= requirements.length <= 5000
- requirements[i].length == 2
- 0 <= skill_i, gate_i < skillCount
- Every pair in requirements is distinct.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def plan_is_feasible(skillCount: int, requirements: list[list[int]]) -> bool:public boolean planIsFeasible(int skillCount, int[][] requirements)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 8 test cases: 8 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's