Uber interview question

Standard leetcode questions, but difficult