Barings Interview Question

Explain how you solved the brainteaser