IBM interview question

Coding question in Python with test cases