Problem · Greedy

Round Prices to Match Target

MediumAirbnbINTERNOA

Given a float array prices and a target value, the task is to round the array such that the total sum equals the target, while minimizing the difference between the rounded array and the original array.

For example, given prices = [1.2, 4.3, 5.8, 6.4] and target = 18, the output should be [1, 4, 6, 7].

Examples
01 · Example 1
prices = [1.2, 4.3, 5.8, 6.4]
target = 18
return = [1, 4, 6, 7]
:)
More Airbnb problems
drafts saved locally
public int[] roundPricesToMatchTarget(float[] prices, int target) {
  // write your code here
}
prices[1.2, 4.3, 5.8, 6.4]
target18
expected[1, 4, 6, 7]
checking account