Help Needed in solving the problem

Revision en2, by DaviddeGea1, 2020-02-09 23:10:41

I got this question in a company's coding round:

Find the minimum cost to make all the elements of an array equal, when 2 operations can be performed-

  1. Increment an element by 1 which costs 'a' units
  2. Decrement an element by 1 which costs 'b' units

Constraints:

Array size <= 10^5

a,b <= 10^5

0 <= element <= 10^6

Tags array, math, #implementation

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English DaviddeGea1 2020-02-09 23:10:41 6 (published)
en1 English DaviddeGea1 2020-02-09 23:10:00 368 Initial revision (saved to drafts)