Hello everyone, This question was asked in Hackwithinfy (9 May 3 pm slot). Please share a possible solution.
You are the manager of the hotel and you have N customers to serve. Each customer has a happiness quotient (Ci) if the food is served to him at time x. The unhappiness of a customer is defined by |Ci — x|. You must serve all the customers and you can serve them in any order. You have to find the minimum sum of unhappiness.
Note: At a particular time only one customer is served and Each customer takes one unit of time.
1 <= N <=10^3 1<= Ci <=N
4 2 2 3 3
Sample output: 2
4 1 1 1 1
Sample output: 6
Please give suggestions on how to solve this problem efficiently.