Winton Group interview question

Binary Trees question on Codility