Uber interview question

Algorithm