Infosys Interview Question

I was asked to explain the logic and pseudo code for a problem statement