Education + Jobs Hiring Website - 2026
0 like 0 dislike
14 views
q3:
You are given an undirected tree with N nodes numbered from 1 to N.
Each node i has an associated value A[i].
For every possible choice of root r:
Root the tree at node r.
Consider every root-to-leaf path.
For each path, compute the sum of node values on the path excluding the root r but including every other node on the path.
Let F(r) be the sum of these values over all root-to-leaf paths.
Your task is to compute
min F(r)
over all possible choices of the root.
Input
N — number of nodes.
Array A of length N, where A[i] is the value of node i.
N-1 undirected edges describing the tree.
Output
Output the minimum possible value of F(r) over all choices of the root.

Q2:
You are given an undirected tree consisting of N nodes numbered from 1 to N.
You need to answer Q independent queries. Each query contains three integers (r, u, v):
Consider the tree to be rooted at node r.
Find the Lowest Common Ancestor (LCA) of nodes u and v with respect to this root.
Input
N — number of nodes.
N-1 undirected edges describing the tree.
Q queries.
Each query contains three integers:
r — the root of the tree for this query.
u, v — the two query nodes.
Output
For each query, output the LCA of u and v when the tree is rooted at r.
Q4 :
partitioning the array into k non overlapping subarrays and finding Min /Max like that
ago in Online Assessments by Expert (147,970 points) | 14 views

Please log in or register to answer this question.