Pregunta de entrevista de Tata Consultancy Services

Coding question was quite confusing