Arista Networks Interview Question

A question about array manipulation and then optimizing it