Accepted solution for https://www.hackerrank.com/challenges/even-tree