ShareChat Coding Question – Solved

7 Live
Efficient Network There are n computer systems connected together to form a network. The network can be represented as a rooted tree (rooted at master computer 1), where the connections are described using two arrays connect_from[]and connect_to[]. Each pair (connect_from[i], connect_to[i]) denotes an undirected edge between the two computers. Additionally, each computer has a value assigned to it denoted by the array computer_val[]. In order to maximize the throughput of the network, certain inefficient systems can be removed. In one operation, any computer node can be chosen, and all computer nodes in its subtree including this node can be removed from the network. Let the number of such operations appfied be num_ops. For a given parameter k, the efficiency of the network after num_ops operations is calculated as: (sum of values of all remaining computer nodes - k * num_ops). Find the maximum possible efficiency after applying some (possibly zero) operations optimally. Note: The node values can be negative. Example Consider the number of computers to be connect_nodes = 4, and their connections to be connect_from = [1, 2, 3], connect_to = [2, 3, 4]. Also, consider the node values to be computer_val = [3, -7, -8, -9] and the given parameter to be k = 5. The given network cΓ₯n be represented as:

Asked in: ShareChat

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |