You are given an integer `n`

, which indicates that there are `n`

courses labeled from `1`

to `n`

. You are also given an array `relations`

where `relations[i] = [prevCourse`

, representing a prerequisite relationship between course _{i}, nextCourse_{i}]`prevCourse`

and course _{i}`nextCourse`

: course _{i}`prevCourse`

has to be taken before course _{i}`nextCourse`

. Also, you are given the integer _{i}`k`

.

In one semester, you can take **at most** `k`

courses as long as you have taken all the prerequisites in the **previous** semester for the courses you are taking.

Return *the minimum number of semesters needed to take all courses*. The testcases will be generated such that it is possible to take every course.

**Example 1:**

Input:n = 4, dependencies = [[2,1],[3,1],[1,4]], k = 2Output:3Explanation:The figure above represents the given graph. In the first semester, you can take courses 2 and 3. In the second semester, you can take course 1. In the third semester, you can take course 4.

**Example 2:**

Input:n = 5, dependencies = [[2,1],[3,1],[4,1],[1,5]], k = 2Output:4Explanation:The figure above represents the given graph. In the first semester, you can take courses 2 and 3 only since you cannot take more than two per semester. In the second semester, you can take course 4. In the third semester, you can take course 1. In the fourth semester, you can take course 5.

**Example 3:**

Input:n = 11, dependencies = [], k = 2Output:6

**Constraints:**

`1 <= n <= 15`

`1 <= k <= n`

`0 <= relations.length <= n * (n-1) / 2`

`relations[i].length == 2`

`1 <= prevCourse`

_{i}, nextCourse_{i}<= n`prevCourse`

_{i}!= nextCourse_{i}- All the pairs
`[prevCourse`

are_{i}, nextCourse_{i}]**unique**. - The given graph is a directed acyclic graph.

class Solution {
public int minNumberOfSemesters(int n, int[][] relations, int k) {
}
}