Infosys OA-2026 February | Tree DP & Re-rooting Technique | On-campus

Infosys · Question · Posted Jun 2026

Question 1: Sum of Distances in Tree Problem Statement There is an unrooted tree consisting of N nodes numbered from 0 to N - 1. You are given the integer N and a 2D array edges where edges[i] = [u, v] indicates that there is an undirected edge between nodes u and v in the tree. Return an array ans of length N where ans[i] is the sum of the distances between the i-th node in the tree and all ...

The full answer & interview discussion are available to premium members.

Log in Create a free account