Pregunta de entrevista de Goldman Sachs

Medium leetcode style question was asked.