Answer: #this is only function you have to use
class Solution:
def countMinOperations(self, arr, n):
arr.sort()
count=0
while(arr.count(0)!=n):
for i in range(n):
if(arr[i]%2==1):
arr[i]=arr[i]-1 #first make all terms even
count=count+1
for i in range(n):
arr[i]=arr[i]//2 #then take half
count=count+1
return count-1
Explanation:
What we have to do here is reduce the no. fruits in all baskets to zero. So first we would identify the baskets with odd fruits and reduce them by one and increment the count for each reduction operation
Then we will take half of all these basket fruits in one operation. We will keep doing this until all baskets have zero fruits.
In the end I returned count-1 as at the last step even when all baskets have zero fruits, count is incremented by one.
Hope this helps you!!