Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Imagine if the courses are nodes of a graph. We need to build an array isReachable[i][j].
Start a bfs from each course i and assign for each course j you visit isReachable[i][j] = True.
Answer the queries from the isReachable array.