IBM Interview Question

There was a coding question to be solved at first.