Algorithm · Salesforce · Medium
An undirected tree consists of n nodes labeled from 0 to n - 1. The tree is connected and does not contain any cycle. In such a graph, every pair of nodes has exactly one simple path. Given n and an edge list edges, where each entry [u, v] describes an undirected edge between node u and node v, compute the tree's diameter. The diameter is the largest number of edges on any simple path between two nodes. Complete the function: Example 1: Explanation: The longest simple path…
Checking your access…