148. All Paths From Source to Target

Given a directed acyclic graph with n vertices (0-indexed), represented as an adjacency list graph, where graph[i] is the list of neighbors of vertex i. Return all paths from vertex 0 to vertex n - 1 as an array of paths (each path is an array of vertices).
Example 1
Input: graph = [[1,2],[3],[3],[]]
Output: [[0,1,3],[0,2,3]]
Explanation: Two paths from 0 to 3: via 1 and via 2.
Example 2
Input: graph = [[4,3,1],[3,2,4],[3],[4],[]]
Output: [[0,1,4],[0,1,2,3,4],[0,1,3,4],[0,3,4],[0,4]]
Explanation: Five paths in a more complex DAG.
graph
JavaScript
Loading...
Line 1, Char 1