Hackerrank solutions in Java