Wrote max function to find the max word in the tree. Program works on sample input but exceeds time limit.