FastPrepTree Diameter
Problems/Tree Diameter

Tree Diameter

Qualcomm logoQualcomm● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamples

Problem statement

Source note: Reported in a Qualcomm phone screen. The report names a well-known problem, Tree Diameter, without restating it. Our version is about 99% the same as the named problem.

You are given an array edges describing an undirected tree. Each entry edges[i] = [u, v] represents an edge between nodes u and v.

The diameter of a tree is the number of edges in its longest path between any two nodes.

Return the diameter of the tree.

Function

treeDiameter(edges: int[][]) → int

Examples

Example 1

edges = [[0,1],[0,2]]return = 2

The longest path is 1 - 0 - 2, which contains 2 edges.

Example 2

edges = [[0,1],[1,2],[2,3],[1,4],[4,5]]return = 4

One longest path is 3 - 2 - 1 - 4 - 5, which contains 4 edges.

Example 3

edges = []return = 0

An empty edge list represents a one-node tree, whose longest path has 0 edges.

More Qualcomm Phone Screen questions

  • First Bad VersionPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • All Nodes Distance K in a Binary TreeAmazon · PHONE SCREEN
  • Frog Position After T SecondsInMobi · PHONE SCREENInMobi interview questions
  • Base Unit ConversionsAdobe · OAAdobe interview questions
  • Diameter of an Acyclic Undirected GraphSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Maximum Data Transfer TimeMicrosoft · OAMicrosoft interview questions
  • Longest Transfer Time in a Server TreeRippling · OARippling interview questions
  • Special Diameter EndpointsAgoda · OAAgoda interview questions
  • Detonate the Maximum BombsZomato / Eternal · PHONE SCREENZomato / Eternal interview questions
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Evaluate DivisionApple · PHONE SCREENApple interview questions
All Qualcomm interview questionsSee Qualcomm hiring insights
Saved
class Solution {
    public int treeDiameter(int[][] edges) {
        // write your code here
    }
}
Checking account…