Given a list of integers, return the number of times it takes produce a list of equal integers by incrementing n - 1 elements by one.
Maths!
The largest number in the list, x, is greater than or equal to the product of s, the smallest number, 1, the number we increment the smallest number by, and m, the number of times we increment, and the value we're after.

Refactoring, we find that the product of m and the number of elements we increment equals the difference between the sum of all elements and the product of the largest element and the number of elements.
 = sum-x*n >= sum-(minNum+m)n)
Refactoring again, we get
*n)
Just solve for
- minToEqual([1, 2, 3]) should return 3
- minToEqual([1, 50000]) should return 49999
- a: solve for sum of elements
- b: solve for minimum value
- c: solve for length of list
- return a - (b * c)
function minMoves(list) {
var sum = list.reduce((a, b) => a + b)
var minNum = Math.min(...list)
var n = list.length;
return sum-(minNum)*n
}
O(n), Linear because of reduce method.