Problem can be found in here!
Solution: Depth-first Search
def allPathsSourceTarget(graph: List[List[int]]) -> List[List[int]]:
def dfs(node: int, path: List[int]) -> None:
if node == target:
paths.append(path)
for neighbor in graph[node]:
dfs(neighbor, path+[neighbor])
paths = []
target = len(graph)-1
dfs(0, [0])
return paths
Time Complexity: , Space Complexity: , where V is the number of courses and E is the length of prerequisites.