Coursera


  • 0
    H

    You are given an array of 'n' numbers. A move is defined by choosing 'n-1' numbers and increasing their value by 1. Find the minimum number of moves you need to make all the numbers equal for that array.

    For example: [1, 2, 3]

    • Choose : [1(0), 2(1)] and array become [2, 3, 3]
    • Choose : [2(0), 3(1)] and array become [3, 4, 3]
    • Choose : [3(0), 3(2)] and array become [4, 4, 4]

    Code:
    return sum(arr) - min(arr)*len(arr)


  • 0
    B

    @himanshu12
    How did you arrive at this solution, and would you mind explaining some of the intuition behind it? Thanks!


  • 0

    @benjie I will try to explain from where the formule comes. Pls, take a look at the picture to get some initial idea.

    0_1476264994937_20161012_121153.jpg


  • 0
    B

    @elmirap what picture?


  • 0

    @benjie Don't you see it? Very strange. I uploaded it together with my post and I can see it in my post.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.