Optimizing Box Weights Hackerrank Solution For Java