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
Core interview problems are free with a full runner and lessons; Pro opens the complete library.