EPAM Systems interview question

They asked me to write code on given senario