Making All Elements of Array Equal

Revision en1, by Social-Verifier, 2022-01-14 13:07:51

Given an Array of N elements and we want to make all elements in array equal we can do 2 following operations

  1. increase any element by 1
  2. decrease any element by 1

What is the minimum number of operation we can do to make all elements in array equal. ?

I tried this problem and found that making every element equal to the median of array is optimal is there any proof for this. ?

Tags array, median

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Social-Verifier 2022-01-14 13:07:51 436 Initial revision (published)