You are given a directed acyclic graph of n nodes labeled 0 to n - 1 as an adjacency list: graph[i] lists every node you can reach from node i in one step. Return every path that starts at node 0 and ends at node n - 1, in any order.
You are given a directed acyclic graph of n nodes labeled 0 to n - 1 as an adjacency list: graph[i] lists every node you can reach from node i in one step. Return every path that starts at node 0 and ends at node n - 1, in any order.
Example 1:
Input: {"graph":[[1,2],[3],[3],[]]}
Output: [[0,1,3],[0,2,3]]
Constraints:
n==graph.length
2≤n≤15
0≤graph[i][j]<n
graph[i][j]=i (no self-loops)
All elements of graph[i] are unique.
The input graph is guaranteed to be a DAG.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"graph":[[1,2],[3],[3],[]]}
The graph has 4 nodes. Every path must start at node 0 and end at node 3.