Question d’entretien chez Goldman Sachs

Medium difficult leetcode style problem.