Tap here to switch tabs
Problem
Submissions

Problem: Minimum Moves to Equal Array Elements II

med
30 min
Try to solve the Minimum Moves to Equal Array Elements II problem.

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

med
30 min
Try to solve the Minimum Moves to Equal Array Elements II problem.

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