Tap here to switch tabs
Problem
Submissions

Problem: Parallel Courses II

Try to solve the Parallel Courses II problem.

Statement

You are given an integer n, indicating that there are n courses labeled from 11 to n. You are also given an array relations where relations[i] = [prevCourse_i, nextCourse_i], representing that course prevCourse_i must be completed before course nextCourse_i can be taken, and an integer k.

In one semester, you can complete at most k courses as long as all prerequisite courses for them have been completed in previous semesters.

Return the minimum number of semesters required to take all n courses.

Constraints:

  • 1≤1 \leq n ≤15\leq 15

  • 1≤1 \leq k ≤\leq n

  • 0≤0 \leq relations.length ≤\leq n $ imes ($n −1)/2- 1) / 2

  • relations[i].length =2= 2

  • 1≤1 \leq prevCourse_i, nextCourse_i ≤\leq n

  • prevCourse_i ≠\neq nextCourse_i

  • All the pairs [prevCourse_i, nextCourse_i] are unique.

  • The given graph is a directed acyclic graph.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Parallel Courses II

Try to solve the Parallel Courses II problem.

Statement

You are given an integer n, indicating that there are n courses labeled from 11 to n. You are also given an array relations where relations[i] = [prevCourse_i, nextCourse_i], representing that course prevCourse_i must be completed before course nextCourse_i can be taken, and an integer k.

In one semester, you can complete at most k courses as long as all prerequisite courses for them have been completed in previous semesters.

Return the minimum number of semesters required to take all n courses.

Constraints:

  • 1≤1 \leq n ≤15\leq 15

  • 1≤1 \leq k ≤\leq n

  • 0≤0 \leq relations.length ≤\leq n $ imes ($n −1)/2- 1) / 2

  • relations[i].length =2= 2

  • 1≤1 \leq prevCourse_i, nextCourse_i ≤\leq n

  • prevCourse_i ≠\neq nextCourse_i

  • All the pairs [prevCourse_i, nextCourse_i] are unique.

  • The given graph is a directed acyclic graph.