HackerRank interview question

question on HashMap and Cycle Detection