Program for solving the utopian tree problem on hackerrank