Algorithm · Google · Hard
You are given n nodes labeled from 0 to n-1, and a list of directed edges where each edge goes from u to v. Additionally, you are given a start node and an end node. Each directed edge can be used in either direction, but with different costs: Traveling along the original direction (u to v) costs 0. Traveling against the original direction (v to u) costs 1. Return the minimum total cost to go from start to end. If no path exists, return -1. A standard unweighted BFS is…
Checking your access…