DE Shaw | Online Assessment | Collect maximum points from Tree | Jan 2025
Question Details
Question1: Min-cost-to-remove-all-array-elements Question 2: A connected unweighted undirected graph with N nodes andN-1 edges (tree) was given where each node were labled from 0 to N-1, Also a value K were given...
Full Details
Question1: Min-cost-to-remove-all-array-elements
Question 2:
A connected unweighted undirected graph with N nodes andN-1 edges (tree) was given where each node were labled from 0 to N-1, Also a value K were given as well.
Each node were having a value, given in an array, where ith index would tell the value of the ith Node where 0<=i<N.
The tree was rooted at 0th Node. You need to collect points from all the node values. Points can be calculated from node values using any two of the given methods.
type 1: Go to a Node sayx and collect array[x]-K to add it in points.
type 2: Go to a Node x divide node value and all of it\'s subtree node\'s values by 2 permanently, then add the current node value post dividing (i.e. arr[x]/2) to points.
Calculate the maximum Points which can be collected by using any of the Types (In each node you can choose any type to collect points independently).
1<=N<=10^5
-10^5<=array[i]<=10^5
-10^9<=K<=10^9
class Solution {
\tpublic int maxPoints(int[] edges, int[] nodeValues, int N, int K) {
\t\t// Write your code here
\t}
}
About This Question
This is a reported interview question from a d.e. shaw interview for a swe role during the oa round reported in 2025.
It covers the following topics: Arrays, Binary Tree, Graph .