Revolut interview question

Python logic problem of live coding