Domanda di colloquio di Pinterest

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