Challenge: Count the Paths Between Two Nodes

Given a graph, print all the paths that exist between two nodes.

Problem statement

Implement a function that counts all the paths that exist between two nodes (source to destination) of an acyclic (not containing cycles) directed graph.

Input

The inputs are a graph, a source value, a destination value.

Output

The output is a value returning the total number of paths.

Sample input

graph = {
    0 -> 1
    1 -> 2
    1 -> 5
    2 -> 3
    2 -> 4
    5 -> 3
    5 -> 6
    3 -> 6
}

source = 0
destination = 6

Sample output

3

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.