Stuck in one of the problem

There are N people in an organization. They are located on different points of the number line.They have decided to meet at a common point.

Find the minimum distance they have to cover in total to meet at a common point.

Constraints
1 <= N <= 100
0 <= Xi <= 10^7

Input:
4 //denotes the value of N
1 3 18 20 //denotes array X

Output:
34

Explaination:

(10-1) + (10-3) + (10 - 18) + (10-20) = 34

Please help me in this problem. Test cases like
[1,2,3,4,5,1000000] is not getting passed. Its correct output is 1000015

Comments (1)