Code for the challenge site hackerrank.com