Pregunta de entrevista de Uber

Standard leetcode questions, but difficult