A possible solution in JS (written in under 20 minutes):
const oasis = [
[4, 6],
[6, 5],
[7, 3],
[4, 5]
]
function rightWay(oasis = []) {
return `start = ${oasis.reduce((previousResult, [newWater, nextWay], index) => {
if (typeof previousResult === 'number' || newWater < nextWay) {
return previousResult
}
const path = [...oasis.slice(index), ...oasis.slice(0, index)]
let water = 0
return path.every(([newWater, nextWay]) => {
water += newWater - nextWay
return water >= 0
})
? index
: previousResult
}, 'impossible')}`
}
console.log(rightWay(oasis))