Algorithm · Google · Medium
Requirements In a directed graph, determine the size of the shortest cycle that passes through a specified vertex v. Implement shortest_cycle_length(edges: list[tuple[int, int]], v: int) -> int, where edges is a list of directed (source, destination) pairs. Examples Input: Edges [(4,5),(5,6),(6,4)], v = 4 Output: 3 Explanation: Starting at 4, the path $$4 \to 5 \to 6 \to 4$$ returns to the chosen vertex after three directed edges. Input: Edges [(3,8),(8,9)], v = 3 Output: -1…
Checking your access…