#3812
Minimum Edge Toggles on a Tree
expert · 1025 · lc hard +32 · 69.1% accepted · 40 likes · top 77%
Description
Given an undirected tree of n nodes with edges edges[i] = [ai, bi] and binary strings start and target of length n, each operation picks an edge [u, v] and flips both endpoints' colors; return the sorted list of edge indices for a minimum-length sequence of operations that transforms start into target, or [-1] if no solution exists.
Code
1
2
3