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-
- Increment an element by 1 which costs 'a' units
- Decrement an element by 1 which costs 'b' units
Constraints:
Array size <= 10^5
a,b <= 10^5
0 <= element <= 10^6