Marc's Cakewalk

Sort by

recency

|

438 Discussions

|

  • + 0 comments

    Simple Python solution :

    def marcsCakewalk(calorie):
        return sum(pow(2, i)*val for i,val in enumerate(sorted(calorie, reverse=True)))
    
  • + 0 comments

    Question's explnation is not clear.

  • + 0 comments
    public static long marcsCakewalk(List<Integer> calorie) {
        Comparator<Integer> comp = Integer::compare;
        List<Integer> cals = calorie.stream().sorted(comp.reversed()).collect(Collectors.toList());
        double mincal = 0;
        for(int i=0;i<cals.size();i++) {
            mincal +=  Math.pow(2, i)*cals.get(i);
        }        
        return (long)mincal;
    }
    
  • + 0 comments

    c++ answer------- long marcsCakewalk(vector calorie) { sort(calorie.begin(),calorie.end(),greater()); long miles=0; for(int i=0;i

  • + 0 comments

    Here is my c++ solution, you can watch explanation here : https://youtu.be/RRJoL2vDmZM

    long marcsCakewalk(vector<int> calorie) {
        sort(calorie.begin(), calorie.end(), [](int l, int r){return l > r;});
        long ans = 0;
        for(int i = 0; i < calorie.size(); i++){
            ans += pow(2, i) * calorie[i];
        }
        return ans;
    }