Amazon interview question

Solve this box sorting game