Optimizing Box Weights Hackerrank Solution