Infosys Interview Question

Codeforces div 4 question .