Extreme Networks interview question

Leetcode easy, 1854. Pretty standard pair programming interview.