Uber Interview Question

The difficulty is around leetcode medium plus.