Practice/Amazon/Leetcode 453. Minimum Moves to Equal Array Elements
CodingMust
You are given an integer array nums of size n. In one move, you can select any element and increment all other n - 1 elements by 1.
Your task is to find the minimum number of moves required to make all elements in the array equal.
n - 1 elements by 1 (leaving one element unchanged)1 <= nums.length <= 10^5-10^9 <= nums[i] <= 10^9Example 1:
Input: nums = [1, 2, 3] Output: 3 Explanation: Start: [1, 2, 3] Move 1: Increment first two elements → [2, 3, 3] Move 2: Increment first two elements → [3, 4, 3] Move 3: Increment first and last → [4, 4, 4]
Example 2:
Input: nums = [1, 1, 1] Output: 0 Explanation: All elements are already equal, so no moves are needed.
Example 3:
Input: nums = [5, 6, 8, 8, 5] Output: 7 Explanation: The minimum value is 5. We need 7 total moves to bring all elements to the same level.