# Minimum Moves to Equal Array Elements II

Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected element by 1.

You may assume the array’s length is at most 10,000.

Example:

$$min_k { \sum_{i=1}^n |n_i - n_k| }$$

$$min_k { \sum_{i=1}^n |n_i - n_k| } = min_k { \sum_{i=1}^k (n_k-n_i) + \sum_{i=k+1}^n(n_i-n_k) } \ = min_k { \sum_{i=1}^k n_k - \sum_{i=1}^k n_i + \sum_{i=k+1}^n n_i - \sum_{i=k+1}^n n_k } \ = min_k { \sum_{i=k+1}^n n_i - \sum_{i=1}^k n_i + (2k - n)n_k }$$