Vector Institute interview question

it is based on the problem statement