Domanda di colloquio di Revolut

How would you solve the following question using python etc