Advansys interview question

Coding problem to give a suggested solution idea