IBM interview question

There was a coding question to be solved at first.