Astroflexx's blog

By Astroflexx, history, 20 months ago, In English

Given an array of integers and an integer m, in one operation, choose atmost m numbers of the array and increment them.

What is the minimum no of operations to make all the elements in the array equal?

1 <= nums[i] <= 1e5

1 <= m <= 1e5

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
20 months ago, hide # |
Rev. 4  
Vote: I like it +2 Vote: I do not like it

assuming the numbers are incremented by one i think you can just sort the array and the biggest value minus the smallest would be the answer

why are you people upvoting my wrong solution this solution is wrong i posted the right one in the replies grahhhhh

»
20 months ago, hide # |
Rev. 4  
Vote: I like it +8 Vote: I do not like it

I think this works.

def solve(nums, m):
    mx = max(nums)
    a = [mx - i for i in nums]
    return max(max(a), (sum(a) + m - 1) // m)