Pregunta de entrevista de DuckDuckGo

Normal Leetcode type of question, medium difficulty