Company: MediaNet_1sep

Difficulty: medium

Problem Statement

Root It Problem Description You are given a tree made of A vertices, and each vertex holds a pile of candies: vertex i holds B[i] candies, as given in the input. A 2-D array C lists the tree's edges, where each row means there is an undirected edge joining C[i][0] and C[i][1]. Pick any vertex to serve as the root, then walk from vertex to vertex only along existing edges, never revisiting a vertex you've already stepped on. For a fixed root, consider every such walk from that root and record the largest total candies collectible along any walk minus the smallest total candies collectible along any walk , using that same root for both. Note: While traversing the tree, you can stop at any vertex you want. In other words, it is not necessary to start from the root and end in a leaf. Across every possible choice of root, report the largest such difference you can find. Input Format The first argument is the integer A. The second argument is an integer array B. The third argument is an 2D i

More MediaNet_1sep OA questionsInterview experiences