Airbnb | Phone screen | Minimize Rounding Error to Meet Target
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2016-06-29Added By Anonymous
Source: Link
Company: Airbnb
Role: g8, g9
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
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. minimize (|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