Uber interview question

The difficulty is around leetcode medium plus.