Uber interview question

DSA LeetCode style question, easy starter, medium follow-up