Infosys interview question

Codeforces div 4 question .