Interview-Question-13: Rounded Sum


Given an array of numbers A = [x1, x2, …, xn] and T = Round(x1+x2+… +xn).
We want to find a way to round each element in A such that after rounding we get a new array B = [y1, y2, …., yn] such that y1+y2+…+yn = T where yi = Floor(xi) or Ceil(xi), ceiling or floor of xi.
We also want to minimize sum |x_i-y_i|。




电子邮件地址不会被公开。 必填项已用*标注