Python String Methods Hackerrank Solution Java