UKG interview question

leetcode easy question, mostly using lists and linkedlists