Pregunta de entrevista de Tata Consultancy Services

Difficult puzzle.