Pergunta de entrevista da empresa StyleSeat

Leetcode style question, more tricky than technical