LinkedIn | Phone screen | Tournament tree problem

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2017-06-23Added By Anonymous
Source: Link

This question was asked recently in the phone interview

1/** 2* A tournament tree is a binary tree 3* where the parent is the minimum of the two children. 4* Given a tournament tree find the second minimum value in the tree. 5* A node in the tree will always have 2 or 0 children. 6* Also all leaves will have distinct and unique values. 7* 2 8* / \ 9* 2 3 10* / \ / \ 11* 4 2 5 3 12* 13* In this given tree the answer is 3. 14*/ 15 16 17class Node { 18 Integer value; 19 Node left, right; 20 Node(Integer value, Node left, Node right) { 21 this.value = value; 22 this.left = left; 23 this.right = right; 24 } 25} 26class Solution { 27 /** 28 * This should return the second minimum 29 * int value in the given tournament tree 30 */ 31 public static Integer secondMin(Node root) { 32 33 } 34}


Comments