Java Substring Comparison Hackerrank Solution