Adyen Interview Question

how to optimise your algorithm