UBS Interview Question

A very tough python algorithm