Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Feature #3: Plot and Select Path

Sumit Rawal answered on May 24, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers


Feature #3: Plot and Select Path

0

The main problem comes down to finding a path between two nodes, if it exists. If the path exists, return the cumulative sums along the path as the result. Given the problem, it seems that we need to track the nodes where we come from. DFS (Depth-First Search), also known as the backtracking algorithm, will be applicable in this case.

Here is how the implementation will take place:

Build the graph using the city map list G_map.

Assign the cost to each edge while building the graph.

Once the graph is built, evaluate each driver’s path in the drivers list by searching for a path between the driver node and the user node.

Return the accumulated sum if the path exists. Otherwise, return -1.

Let’s look at the code for the solution: 

Popularity 1/10 Helpfulness 1/10 Language scala
Source: Grepper
Link to this answer
Share Copy Link
Contributed on May 24 2023
Sumit Rawal
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.