packages
array.minWastedSpace
to a very large number.boxes
array.
a. Sort the boxes
array.
b. If the largest box is smaller than the largest package, continue to the next supplier.
c. Initialize totalBoxSize
to 0 and index
to 0.
d. Iterate over each boxSize
in boxes
:
i. Use binary search to find the rightmost package that can fit into boxSize
.
ii. Update totalBoxSize
by adding the product of boxSize
and the number of packages that fit.
iii. Update index
to the position after the last package that fits.
e. Calculate the wasted space for this supplier and update minWastedSpace
if it's smaller.minWastedSpace
is still very large, return -1, else return minWastedSpace
modulo 10^9 + 7.