All problems
0030MediumDepth-First SearchBreadth-First SearchGraph TheoryTopological SortDirected Acyclic Graph

Apprenticeship Skill Plan

Tracked in this browser only
Write code

Trains the technique from

LeetCode 207Course Schedule

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def plan_is_feasible(skillCount: int, requirements: list[list[int]]) -> bool:
Java
public boolean planIsFeasible(int skillCount, int[][] requirements)
September 7
Apply