Practice Create Components With Same Value
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Create Components With Same Value
Problem Statement
There is an undirected tree with n nodes labeled from 0 to n - 1. You are given a 0-indexed integer array nums of length n where nums[i] represents the value of the ith node. You are also given a 2D integer array edges of length n - 1 where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are allowed to delete some edges, splitting the tree into multiple connected components. Let the value of a component be the sum of all nums[i] for which node i is in the component. Return the maximum number of edges you can delete, such that every connected component in the tree has the same value.
Source: Create Components With Same Value on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [6,2,2,2,6], edges = [[0,1],[1,2],[1,3],[3,4]]
2
# Example 2
nums = [2], edges = []
0
Constraints
Related LeetCode Problems
Practice more problems similar to Create Components With Same Value.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.