HCLTech interview question

Coding question in docs format