Calculate the height of a tree

In this post, we define the height of a tree as the number of nodes in the path between the root node of the tree and the leaf node that is the furthest from the root node. See the following illustration for examples: Note that even though the trees in the examples above only have at most 2 branches, we don't need to make such an assumption. We can define a Java class to represent the tree as follows: @Builder @Value public class Tree < T > { T value ; List < Tree < T >> branches ; } We define an interface for calculating the height of the tree as follows: interface TreeHeightSolver < T > { int treeHeight ( Tree < T > tree); } Recursive solution We can recursively move down to each branch of the tree, find the height of the branch, and pick the branch with the greatest height, and add 1 to get the height of the tree. See the solution below: public class RecursiveTreeHeightSolver < T > implements TreeHeightSolver < T > { @Ove...