IBM Interview Question

An average difficulty python algorithm question