BREAKING! Its sister question was found --> Checkout LC 343. Integer Break <--
You are given a mystical tree with w nodes. Each node is connected to at least one other node by an edge. Your task is to sever one or more edges in the tree to split it into subtrees. The goal is to maximize the product of the sizes of these subtrees. The size of a subtree is defined as the number of nodes it contains. The product of subtree sizes is calculated by multiplying the sizes of all subtrees together.
Write a program that takes as input the number of nodes in the tree and the edges between them, and outputs the maximum product of subtree sizes achievable after severing edges in the tree.
Input Format
The first line of input contains an integer N, representing the number of nodes in the mystical tree.
The next N-1 lines each contain two space-separated integers U and V, signifying an edge between the respective nodes.
Output Format
Print a number X, representing the maximum product of subtree sizes achievable after edge deletions.
w = 5 edges = [[1, 2], [2, 3], [3, 4], [4, 5]] return = 6
Cut the 3-4 edge. Subtrees formed are 1-2-3 and 4-5, so the product is 3 * 2 = 6.
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public long maximizeProductOfSubtreeSizes(int w, int[][] edges) {
// write your code here
}