IBM interview question

Coding challenge from hacker rank