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.
This is my java 8 solution, feel free to ask me any questions.
First look
publicstaticlongmarcsCakewalk(List<Integer>calorie){//Perform sort the given caloriescalorie.sort(null);calorie.sort(Collections.reverseOrder());longsumCalories=0;//Calculate sum caloriesfor(inti=0;i<calorie.size();i++){longcurrent=(long)Math.pow(2,i)*calorie.get(i);sumCalories=sumCalories+current;}returnsumCalories;}
Second look (little bit changed using bitwise manipulation)
longcurrent=(1L<<i)*calorie.get(i);
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 →
This is my java 8 solution, feel free to ask me any questions.
First look
Second look (little bit changed using bitwise manipulation)