Lyft interview question

Leetcode hard