Categories
Mastering Development

What is the best algo for this array minimization problem?

I have an array say ‘A’ of size n having some numbers {a1, a2, …, an} not necessarily distinct. I have to create another array B = {b1, b2, …, bn} which are distinct such that the value of sum|ai – bi| over all i’s{i =1 to i =n} is minimized. Basically I want to […]