Uber interview question

Coding question - average difficulty