Solving HackerRank's Utopian Tree