Company: Meesho

Difficulty: medium

Problem Statement

Minimum Leaves To Remove For A Special Tree The country of Hackerland can be represented as a tree of tree_nodes nodes indexed from 1 to tree_nodes . The i -th edge is a bidirectional connection between the nodes numbered tree_from[i] and tree_to[i] and has a weight tree_weight[i] . Each node i is associated with an integer arr[i] . The tree is rooted at node index 1 . A tree is special if there is no pair of vertices with indexes x and y such that: y lies in the subtree of x , and arr[y] < distance(x, y) , where distance(x, y) is the sum of the weights of the edges on the path between nodes x and y . A leaf of the tree is a node connected to a single node by a single edge. In one operation, any one leaf is removed from the tree. The root of the tree cannot be removed. Find the minimum number of leaves that must be removed in order to make the tree special. Function getMinLeavesToRemove(tree_nodes, tree_from, tree_to, tree_weight, arr) -> int Complete the function getMinLeavesToR

More Meesho OA questionsInterview experiences