public class Solution {
public int minMoves(int[] a) {
//incrementing n-1 elements to reach max is equivalent to
//decrementing max elemnt by (max-min)) to reach the rest
int count = 0;
boolean proceed = true;
while(proceed){
int max = a[0];
int min = a[0];
int idx = 0;
proceed = false;
for(int i=1; i < a.length; i++){
if(max < a[i]){
max = a[i];
idx = i;
proceed = true;
}
if(a[i] < min){
min = a[i];
}
}
a[idx] -= (max-min);
count += (max-min);
}
return count;
}
}

@Matthew_Lin the final algorithm？Are you asking why the dp solution need Arrays.sort(nums)? From the before three trying, we can see that we want to handle the smaller num first moment, because comparing to the bigger one, smaller num must need more add 1.

Well, I think this problem is trying to challenge how you can re-translate a "move" to see how far a value is above the array' minimum. Once, the translation is done, the coding itself is pretty simple.