Pregunta de entrevista de Tata Consultancy Services

Asked logic for simple problem