We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static int chiefHopper(List<Integer> arr){
////////////////////
// Rather than iterating with the different inital energy to find the positive end energy, I should start with +ve end energy
// and iterate in the last to first to find the minimum positive energy.
// To calculate this, consider the end energy is 1.
// The energy before jumping the last building should be :
// newEnergy = currentEne + delta (currnetEne - height);
// newEnergy = 2 * currentEne - height; => We need to have newEnergy >= 0 & need to find the currentEnergy.
// currentEne = newEnergy + height / 2;
double newEne = 0;
double currentEne = 0;
for(int i = arr.size() - 1; i >= 0; i--){
currentEne = Math.ceil( (newEne + arr.get(i)) / 2 );
newEne = currentEne;
}
return (int)currentEne;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Chief Hopper
You are viewing a single comment's thread. Return to all comments →