code for hacker rank weekly challenge 9