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
↵
↵
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