Error
|
|
---|---|
@Ibrahim Nash | 5765 |
@blackshadows | 5715 |
@akhayrutdinov | 5111 |
@mb1973 | 4993 |
@Quandray | 4944 |
@saiujwal13083 | 4506 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3516 |
@sushant_a | 3459 |
@verma_ji | 3341 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@aroranayan999 | 1276 |
@bt8816103042 | 739 |
@rohitanand | 495 |
@codeantik | 479 |
@shalinibhataniya1097 | 472 |
@amrutakashikar2 | 464 |
@thealchemist627 | 456 |
@akashkale117 | 453 |
@shivanandp12345678910 | 453 |
@dalwainazism125 | 453 |
@SherlockHolmes3 | 447 |
Complete Leaderboard |
Given a directed acyclic graph(DAG) with n nodes labeled from 0 to n-1. Given edges, s and d ,count the number of ways to reach from s to d.There is a directed Edge from vertex edges[i][0] to the vertex edges[i][1].
Example:
Input: edges = {{0,1},{0,3},{1,2},{3,2}},
n = 4, s = 0, d = 2
Output: 2
Explanation: There are two ways to reach at
2 from 0. These are-
1. 0->1->2
2. 0->3->2
Your Task:
You don't need to read or print anything. Your task is to complete the function possible_paths() which takes edges, n, s and d as input parameter and returns the number of ways to reach from s to d.
Expected Time Compelxity: O(2n)
Expected Space Complexity: O(n+e)
where e is the number of edges in the graph.
Constraints:
1 <= n <= 15
0 <= s, d <= n-1
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes