Bank of America interview question

A python algorithm question