Cashgro Interview Question

How can we optimise the assignment better.