Pregunta de entrevista de Palantir Technologies

About a medium difficulty Leetcode question, then runtime.