Pregunta de entrevista de Arista Networks

Leetcode question with basic and optimized approach