Pregunta de entrevista de Amazon

LeetCode Medium and sometimes hard question