Pregunta de entrevista de Crossover for Work

Leetcode style, medium difficulty question.