HackerRank Java Substring problem solution - TheCScience