Quick actions

cmd+k|ctrl+k

Navigation

Languages

Hacker rank Bill

Snippet info

Language

JavaScript

Visibility

public

Author

krishnakanth

Created

2022-11-23T15:15:10.451691Z

Updated

2022-11-23T15:15:10.451691Z

//also use arr.reverse
function processData(input) {
    
    let string = input.split('\n');
    let k = string[0].split(" ")[1];
    let bill = string[1].split(" ").map(Number);
    let b =  string[2]
    let res = 0
    const total  = bill.reduce((a, b)=>{
        return a+b;
    });
    const discount = bill[k];
    const refund =  b - (total - discount) / 2;
    if (refund != 0){
    console.log(refund);
    }else{
        console.log("Bon Appetit");      
    }
    
}

  
            
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
    processData(_input);
});

        
INFO