Arista Networks interview question

Leetcode question with basic and optimized approach