Minimum Direction Violations
Asked at Google
Reported by the problem's creator, not verified
You are given a directed graph with n nodes numbered 0 to n - 1 and a list of directed edges, where each edge [u, v] goes from u to v. You may traverse an edge in its own direction for free, or against its direction at a cost of 1. Edges may be traversed any number of times in either direction, and parallel edges and self loops may appear.
Examples
Example 1
Input: n =
5, edges =[[0,1],[2,1],[2,3],[4,3]], start =0, end =4Output:
2Explanation: The walk 0, 1, 2, 3, 4 uses edge [0,1] forward, edge [2,1] backward, edge [2,3] forward and edge [4,3] backward, so two edges are walked against their direction.
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.