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

  1. Example 1

    Input: n = 5, edges = [[0,1],[2,1],[2,3],[4,3]], start = 0, end = 4

    Output: 2

    Explanation: 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.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.