Box Stacking Problem Leetcode Python