IBM Interview Question

Coding challenge from hacker rank