Grant Street Group Interview Question

Probably an easy-medium level leetcode problem.