All Paths From Source To Destination

Problem Statement:

You are given a directed acyclic graph of n nodes labeled from 0 to n - 1. Find all possible paths from node node 0 to node node (n - 1). You can return them in any order.

The graph is represented by adjacency list: graph[i] is a list of all nodes you can visit from node i. There is a directed edge from node i to node graph[i][j].

Given graph = [[1,2],[3],[3],[]]
Output: [[0,2,3],[0,1,3]]
There are two paths: 0 -> 2 -> 3 and 0 -> 1 -> 3 .


Login to Access Content

Don't forget to take in-depth look at the other backtracking problems because that is what would make you comfortable with using the backtracking template and master the art of Backtracking:


If you have any feedback, please use this form:

Help Your Friends save 25% on our products