Google | Phone Screen | India | SDE
Anonymous User
1119

I am a front end developer but google tagged me for software development -backend. In starting of interview we discussed this issue after that there was only one question.

you have a car to go from A to B and you need to find out how can you travel in least amount of fuel. you will have multiple fuel points in between source and destination. your car is empty you will fill it in first fuel point.

Input -> Array = [ {
ID: 1
DfromA: 0km,
perlitre: 70
},
{
ID: 2
DfromA: 20km,
perlitre: 100
},
{
ID:3
DfromA: 30km,
perlitre: 50
}]

tank_capacity = 25
distance = 40

Expected Expected output = [
{ID: 1
fuel: 20 lts
},
{ID: 2
fuel: 5
},
{ID: 5
fuel: 25lts
}
]

Assumptions car consumes 1 litre per 1 km.

function calculate(arr, tankCapacity, Distance) {
// implementation
}

Follow up
in case anyone has ideas on how to solve this problem or approach this problem, please share.
It would be useful for future reference. Thanks!

Comments (3)