UBS interview question

Solve math problem Solve algo problem in Python