Optimizing Box Weights Leetcode Sql