Leetcode Problem 1786. Number of Restricted Paths From First to Last Node
1786. Number of Restricted Paths From First to Last Node
Leetcode Solutions
Dijkstra & Cached DFS - Clean & Concise
Create a graph representation from the edges list.
Use Dijkstra's algorithm to find the shortest distance from node n to all other nodes.
Implement a DFS function that counts the number of restricted paths from the current node to the last node, using the distances calculated by Dijkstra's algorithm.
Use memoization to cache the results of the DFS function to avoid recalculating paths.
Return the result of the DFS function starting from node 1.