2673. Make Costs of Paths Equal in a Binary Tree
You are given an integer
nrepresenting the number of nodes in a perfect binary tree consisting of nodes numbered from1ton. The root of the tree is node1and each nodeiin the tree has two children where the left child is the node2 * iand the right child is2 * i + 1.Each node in the tree also has a cost represented by a given 0-indexed integer array
costof sizenwherecost[i]is the cost of nodei + 1. You are allowed to increment the cost of any node by1any number of times.Return the minimum number of increments you need to make the cost of paths from the root to each leaf node equal.
Note:
- A perfect binary tree is a tree where each node, except the leaf nodes, has exactly 2 children.
- The cost of a path is the sum of costs of nodes in the path.
1 | class Solution { |