Amazon Interview Question

Solve this box sorting game