Hackerrank Java Loops Ii Solution Tree