Round Numbers


  • 0
    S

    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:

    sum(Y) = round(sum(x))
    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

    vector<int> custom_round(vector<double> input) {
     // ...
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.