Adyen interview question

complexity of the solution