Hi all, I am wondering why my solution didn't get accepted. The task aim is to find the minimum number of operations to reduce the sum of nums by at least half. I know I might be wrong, but by looking at my output, I would say that my answer is better than the expected answer is. If so, could you please explain why my solution should be wrong? Thanks!
I get the wrong answer message only with this input:
[92,91,55,74,98,45,94,99,35,28,78,10,27,55,93,93,33,76,14,27,82,11,5,58,96,70,31,6]
My output is:
19
Expected output is:
22
class Solution:
def halveArray(self, nums: List[int]) -> int:
halved = nums
o = 0
while sum(halved) > (sum(nums) / 2):
o += 1
m = max(halved)
halved = [i/2 if i==m else i for i in halved]
return o