Search This Blog




marc's cakewalk hacker rank solution javascript


Please refer this link for the problem statement click here




Javascript program for marc's cakewalk hackerrank solution


function marcsCakewalk(calorie) {
    let result = 0;
    calorie.sort((a, b) => b - a);

    for (let i = 0; i < calorie.length; i++) {
        result += (2 ** i) * calorie[i];
    }
    return result;
}



Time Complexity : O(nlogn)

Space Complexity : O(1)






Post a Comment

0 Comments