The following interesting question was asked in a programming contest.
Given the following input string array to represent a tree, write code to find diameter of the tree
INPUT:
inputExample[] = [empty,empty,D1,D2,D3,D4,D5,D6,empty,C1,empty,C2,C3,D7,D8,empty,empty,empty,empty,empty,empty,empty,empty,empty,empty,C4,empty,C5,C6,empty,empty,empty,empty]
CODE:
int diameter(String[] input)
{
....? (what goes here?)
}
Sample output: 6 in the above case
Basically the example represents the following diagram - find the diameter
Aucun commentaire:
Enregistrer un commentaire