Arista Networks interview question

1st stage: HackerRank easy to medium problem