Leetcode Problem 1462. Course Schedule IV

1462. Course Schedule IV

Leetcode Solutions

Floyd–Warshall Algorithm for Course Prerequisites

  1. Initialize a 2D array connected of size numCourses x numCourses with False values.
  2. Set connected[i][j] to True for each direct prerequisite (i, j).
  3. Perform the Floyd–Warshall algorithm:
    • For each course k, update connected[i][j] to True if connected[i][k] and connected[k][j] are True for all pairs (i, j).
  4. For each query (u, v), check if connected[u][v] is True and return the result in an answer list.
UML Thumbnail

DFS-based Prerequisite Check

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...