Question d’entretien chez Morgan Stanley

solve this problem in python