FastPrepFastPrep
Problem Brief

Round Prices to Match Target

INTERNOA

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].

1Example 1

Input
prices = [1.2, 4.3, 5.8, 6.4], target = 18
Output
[1, 4, 6, 7]
Explanation
:)
public int[] roundPricesToMatchTarget(float[] prices, int target) {
  // write your code here
}
Input

prices

[1.2, 4.3, 5.8, 6.4]

target

18

Output

[1, 4, 6, 7]

Sign in to submit your solution.