Microsoft Interview Question

How would you solve this python problem.