Lyft interview question

Medium LeetCode question?. Not that hard