Pergunta de entrevista da empresa Crossover for Work

Leetcode style, medium difficulty question.