Uber interview question

2 medium 1 hard leetcode