Arista Networks Interview Question

1st stage: HackerRank easy to medium problem