Question d’entretien chez Revolut

How would you solve the following question using python etc