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.
Sort the list,
take the last element of the list each time, to get the least possible total of miles. Decrement your counter as you go.
public static long marcsCakewalk(List<Integer> calorie) {
long result = 0;
calorie.sort(null);
int index = calorie.size()-1;
for(int power = 0; power < calorie.size();power++){
result += Math.pow(2, power)*calorie.get(index);
index--;
}
return result;
return result;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Marc's Cakewalk
You are viewing a single comment's thread. Return to all comments →
Sort the list, take the last element of the list each time, to get the least possible total of miles. Decrement your counter as you go.
return result; }