Pergunta de entrevista da empresa Pinterest

Given the array of rectangles' lengths, implement the Pinterest waterfall grind.