Minimum Edge Toggles on a Tree
You are given an undirected tree consisting of n nodes, numbered from 0 to n - 1. The tree's structure is provided by a 2D array edges of length n - 1, where edges[i] = [u, v] represents an edge between node u and node v.
You are also given two binary strings, start and target, both of length n. For any node x, start[x] represents its initial color and target[x] represents its desired color ('0' or '1').
In one operation, you can choose an edge by its index i and toggle both of its endpoints. Toggling a node flips its color from '0' to '1' or from '1' to '0'.
Find the minimum number of edge toggles required to transform the start string into the target string. Return an array of the flipped edge indices sorted in increasing order.
If it is impossible to achieve the target configuration, return an array containing a single element [-1].
Example 1:

Input: n = 4, edges = [[0,1], [0,2], [0,3]], start = "0000", target = "0110"
Output: [0, 1]
Explanation:
Nodes 1 and 2 need to flip, while nodes 0 and 3 must remain unchanged. Toggle edge 0 (connects 0 and 1). Nodes 0 and 1 flip. The string becomes "1100".
Toggle edge 1 (connects 0 and 2). Nodes 0 and 2 flip. The string becomes "0110". The string perfectly matches the target. The used edges are 0 and 1.
Example 2:

Input: n = 3, edges = [[0,1], [1,2]], start = "000", target = "111"
Output: [-1]
Explanation:
There are 3 nodes that need to flip. Every edge toggle flips exactly two nodes. It is mathematically impossible to change the parity of an odd number of nodes using operations that flip nodes in pairs. Thus, we return [-1].
Now Your Turn!
Pick the correct output for the given inputInput: n = 4, edges = [[0,1],[1,2],[2,3]], start = "0000", target = "1001"
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 2 <= n == start.length == target.length <= 105
- edges.length == n - 1
- edges[i] = [a, b]
- 0 <= a, b < n
- start[i] and target[i] are either '0' or '1'.
- The input guarantees that edges represents a valid tree.