Maximum Bags With Full Capacity of Rocks
We can approach this problem by iterating through the bags and attempting to fill them using the available additionalRocks
. We’ll sort the bags by the number of rocks needed to reach full capacity, so we can prioritize filling the bags that require fewer rocks.
Here’s a stepbystep solution:
 Calculate the number of rocks needed for each bag to reach full capacity and store this information in a list.
 Sort the list in ascending order.
 Iterate through the sorted list, filling bags until you run out of
additionalRocks
.  Return the number of bags that have reached full capacity.
Below is the code that implements these steps:


This code will return the maximum number of bags that could have full capacity after placing the additionalRocks
in some bags.