TreeHeight Codility problem