Tap here to switch tabs
Problem
Submissions

Problem: Minimum Moves to Equal Array Elements II

Minimum Moves to Equal Array Elements II asks you to find the fewest one-step increments or decrements needed to make every value in an integer array the same, including when values are negative.

Statement

Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.

In a single move, you can increment or decrement an element of the array by 11.

Constraints:

  • n == nums.length

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Moves to Equal Array Elements II

Minimum Moves to Equal Array Elements II asks you to find the fewest one-step increments or decrements needed to make every value in an integer array the same, including when values are negative.

Statement

Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.

In a single move, you can increment or decrement an element of the array by 11.

Constraints:

  • n == nums.length

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9