Skip to content

Files

Latest commit

bf046cb · May 23, 2019

History

History
This branch is up to date with piyush01123/Daily-Coding-Problems:master.

160

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
May 11, 2019
May 23, 2019

This problem was asked by Uber.

Given a tree where each edge has a weight, compute the length of the longest path in the tree.

For example, given the following tree:

   a
  /|\
 b c d
    / \
   e   f
  / \
 g   h

and the weights: a-b: 3, a-c: 5, a-d: 8, d-e: 2, d-f: 4, e-g: 1, e-h: 1, the longest path would be c -> a -> d -> f, with a length of 17.

The path does not have to pass through the root, and each node can have any amount of children.