Code Interview Questions Implementation
Please see the latest version by the following shared Notion link.
https://www.notion.so/Tree-Decrement-e84e1514b19f4f819ff1916ee89a9ed1?pvs=4
Tree Decreasment
A tree can be represented as an unweighted undirected graph of
A value
Given the tree,
Example
Suppose
Possible Solution:
To minimize the cost, we'd like to see the best secriano (all nodes have a even value, which implies that they can complete the decreasement with 0 cost in total).
Also, since the question gurantees that the given tree can be decreased to 0, which means there must be a "true" pair for each node
Given a 2-d array arr of size n x m, a selection is defined as an array of integers such that it contains ateast ( m/ 21 integers from each row of arr. The cost of the selection is defined as the maximumdifference between any two integers of the selection. Suppose kis the minimum cost of all the possible selections for the given 2-d array. Find themaximum value of the product of k* the number of integers considered in the selection with theminimum cost.
Example
Suppose n = 3, m = 2, and arr = [[1, 2], [3, 4], [8, 9]] Some of the possible selections are [2, 3, 8], [1, 2, 3, 9], [1, 3, 4, 8, 9] etc. The cost of these selectionsare 8 - 2 = 6, 9 - 1 = 8, and 8 respectively. Here the minimum cost of all the possible selections is 6. The possible selections with the cost 6 are2, 4, 8] and [2, 3, 4, 8]. The maximum value of the required product is obtained using the latterselection i.e.6*4 = 24. Hence the answer is 24. Function DescriptionComplete the function getMaxProductin the editor below. getMaxProduct has the following parameter:int arrln][m]: the given 2-d array Returns int: the maximum possible product