@yuchenlin Let's consider special case, when array has only two elements [a,b]. Then there are three cases:

k<a && k<b
k>a && k> b
k<a && k>b

In the first case number of moves equals a-k+b-k, and it is not hard to mention that the expression has minimum when k -> b or k->a. The second case is analogically the same. In the third case moves = a-k+k-b = a-b, which already shows that anyway result will be the same if k = a or k == b.

Now let's consider when there are 3 elements [a,b,c]. Let's skip the cases when k is more than all elements and k is less than all elements, because it is clear that minimum cannot be reached for that cases. Then we have two cases:

k>a && k> b && k<c
k>a && k>b && k<c

In the first case, moves = k-a+k-b+c-k = k - a - b + c, thus you can understand that k must be equal to a or b to minimize the moves. The second case shows analogically the same thing. Know let's consider general case when array has n elements [a1,a2,a3,... an]. The same way as in previous example, let's skip the corner cases when k is larger than all elements and k is less than all elements. Then moves = k - a1 + k - a2 + ...+ k - ai + a(i+1) -k + a(i+2) -k +...+ an-k. (where k >ai && k<a(i+1)) As a result k's in the expression will compensate each other and it gives some the expression like an +a(n-1)+...+ai-k+a(i-1) -k +...+aj-k-a(j-1)-a(j-2)- ...-a2-a1. From here it is understandable that k must be equal to ai in order to minimize the result of the expression. Analogically you can see that fact considering the case when k is more than most of the elements.

P.S: Actually, it is also understandable from that explanation that minimum can be reached when k equals to the median element.