Barclays interview question

Coding problem statement to solve