Practice Course Schedule IV
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Course Schedule IV
Problem Statement
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course ai first if you want to take course bi. Prerequisites can also be indirect. If course a is a prerequisite of course b, and course b is a prerequisite of course c, then course a is a prerequisite of course c. You are also given an array queries where queries[j] = [uj, vj]. For the jth query, you should answer whether course uj is a prerequisite of course vj or not. Return a boolean array answer, where answer[j] is the answer to the jth query.
Source: Course Schedule IV on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
numCourses = 2, prerequisites = [[1,0]], queries = [[0,1],[1,0]]
[false,true]
# Example 2
numCourses = 2, prerequisites = [], queries = [[1,0],[0,1]]
[false,false]
# Example 3
numCourses = 3, prerequisites = [[1,2],[1,0],[2,0]], queries = [[1,0],[1,2]]
[true,true]
Constraints
Related LeetCode Problems
Practice more problems similar to Course Schedule IV.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.