Pergunta de entrevista da empresa Tata Consultancy Services

Coding question was quite confusing