Medium · Math
Minimum Moves to Equal Array Elements
Given a nonempty integer array nums of at most 10⁵ values in [−10⁹, 10⁹], return the minimum number of moves needed to make all elements equal, where one move adds 1 to n − 1 of the elements.
Examples
Example 1
[1,2,3] → 3Output: 3 moves
Example 2
[1,1,2,4] → 4Output: 4 moves
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.