Redundant Connection II

The problem involves a directed graph that initially was a rooted tree with n nodes, where all nodes have distinct values from 1 to n. An additional directed edge has been added to this tree, which created a cycle. The task is to identify an edge which, when removed, will restore the graph to a rooted tree. If there are multiple possible edges to remove, return the one that appears last in the provided edge list.

Constraints

  • n == edges.length
  • 3 <= n <= 1000
  • edges[i].length == 2
  • 1 <= ui, vi <= n
  • ui != vi
Saving… · 2 lines
class Solution:
def redundantConnectionII(self, edges: List[List[int]]) -> List[int]:
Console

Click Run to execute sample tests.