Airbnb | Phone screen | Minimize Rounding Error to Meet Target

Was asked in airbnb phone screen

When you book on airbnb the total price is:

Total price = base price + service fee + cleaning fee + ...

input : array of decimals ~ X
output : array of int ~ Y

But they need to satisfy the condition:

  1. sum(Y) = round(sum(x))
  2. minmize (|y1-x1| + |y2-x2| + ... + |yn-xn|)

Example1:
input = 30.3, 2.4, 3.5
output = 30 2 4

Example2:
input = 30.9, 2.4, 3.9
output = 31 2 4

https://leetcode.com/problems/minimize-rounding-error-to-meet-target

Comments (13)