Lyft interview question

Leetcode medium task, same as discussed here