Trains the technique from
LeetCode 1462Course Schedule IVThis 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 course has count modules numbered 0 through count - 1. Each entry before[i] = [a, b] says module a has to be taken before module b. A module x is a forerunner of a module y when some chain of those requirements leads from x to y.
Each entry asks[i] = [u, v] is a question: is u a forerunner of v?
Return the answers in the order the questions are asked. The requirements never lead round in a circle.
Example 1
Module 0 comes before 1 and 1 before 2, so the chain makes 0 a forerunner of 2. Neither of the other two questions runs the right way along the chain.
Example 2
There are no requirements at all, so no module is a forerunner of any other.
Example 3
Module 0 reaches 3 through either 1 or 2. Modules 1 and 2 sit side by side with no chain between them, and no requirement touches module 4 at all.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def check_if_prerequisite(count: int, before: list[list[int]], asks: list[list[int]]) -> list[bool]:public List<Boolean> checkIfPrerequisite(int count, int[][] before, int[][] asks)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.