Pregunta de entrevista de Goldman Sachs

Medium difficult leetcode style problem.