As reported: Visa Senior Data Engineer (Java / Big Data, Bangalore), round 2 — 45 minutes of coding and data structures (2025): LeetCode Parallel Courses II first (the interviewer expected a direct solution within about 5 minutes), then Non-overlapping Intervals and Minimum Moves to Equal Array Elements II, then Java / Spring / Spark theory.
There are n courses labelled 1..n. relations[i] = [prev, next] means prev must be taken in an earlier semester than next. Each semester you can take at most k courses whose prerequisites were all completed in earlier semesters. Return the minimum number of semesters to take all courses. The prerequisites form a DAG, so it is always possible.
This is LeetCode 1494 — Parallel Courses II.
Example
n = 4, relations = [[2,1],[3,1],[1,4]], k = 2 -> 3
n = 5, relations = [[2,1],[3,1],[4,1],[1,5]], k = 2 -> 4
Constraints: 1 ≤ n ≤ 15; 1 ≤ k ≤ n; 0 ≤ relations.length ≤ n·(n−1)/2; no repeated relations; the graph is acyclic.
Code runner format: one JSON value per line: n, relations, k. Implement minNumberOfSemesters(n, relations, k); the harness prints the number.