Bank of America Interview Question

A python algorithm question