Pregunta de entrevista de Tata Consultancy Services

HR gave a problem and asked me to write a code