How to find the seeding number for acheiving the minimum cost?

24 Views Asked by At

Consider there are n integers. I have to pick one Random integer 'R' and i have to subtract 'R' with each element of the 'N' integers. Result has to be added. Result that i will achieve should be the minimum value

Consider the usecase:

N elements : 1 5 10

Consider i am choosing 10 as random number Now,

|1-10|+|5-10|+|10-10| = 14

Consider i am choosing another random number '5'

|1-5|+|5-5|+|10-5| = 9

So choosing the random number 5 is best because final result is lower when compared to the previous one.

Here random number '5' is not an answer too. I need to pick the correct number to achieve the minimum cost.

How to solve this problem without brute force method?

1

There are 1 best solutions below

2
On BEST ANSWER

The median of the data set may work as an answer..