Backbase interview question

Explain the algorithm you wrote