Pregunta de entrevista de Tata Consultancy Services

One coding question about the logic