Skip to content

Practice Minimum Score After Removals on a Tree

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2322
LeetCode Problem

Minimum Score After Removals on a Tree

Problem Statement

nums[i] is the value of node i and edges contains the undirected tree edges [a,b]. Remove exactly two different edges, producing three connected components. Compute the XOR of node values in each component; the score is the largest of those three XOR values minus the smallest. Return the minimum possible score.

Source: Minimum Score After Removals on a Tree on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,5,5,4,11], edges = [[0,1],[1,2],[1,3],[3,4]]
Output
9

# Example 2

Input
nums = [5,5,2,4,4,2], edges = [[0,1],[1,2],[5,2],[4,3],[1,3]]
Output
0

Constraints

n == nums.length
3 <= n <= 1000
1 <= nums[i] <= 10^8
edges.length == n - 1
edges[i].length == 2
0 <= ai, bi < n
ai != bi
edges represents a valid tree.

Related LeetCode Problems

Practice more problems similar to Minimum Score After Removals on a Tree.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.