Uber interview question

Coding question (leetcode easy or medium)