Блог пользователя Astroflexx

Автор Astroflexx, история, 20 месяцев назад, По-английски

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

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
20 месяцев назад, скрыть # |
Rev. 4  
Проголосовать: нравится +2 Проголосовать: не нравится

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 месяцев назад, скрыть # |
Rev. 4  
Проголосовать: нравится +8 Проголосовать: не нравится

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)