825. Find All Paths in DAG (Count, u to v)

HardRecursionRecursion

Given a DAG with n nodes and directed edges, count all simple paths from node u to node v. Input: JSON {n, edges, u, v}.

Input: JSON {n, edges, u, v}.

Output: Integer count.

Examples

Example 1
Input: {"n":4,"edges":[[0,1],[0,2],[1,3],[2,3]],"u":0,"v":3}
Output: 2
Explanation: 0->1->3 and 0->2->3.
Example 2
Input: {"n":3,"edges":[[0,1],[1,2]],"u":0,"v":2}
Output: 1
Explanation: Single path.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →