Solving tree traversal problem from http://code-warrior.herokuapp.com.