Problem of the Day
A new programming or logic puzzle every Mon-Fri

Sum Largest

Hey hey! Happy Monday

Today's problem is to create a function that takes in an array and some integer N. The goal of the function is to return the sum of the N largest integers. Here's an example:

nums = [1,2,3,4,5,6,7,7,7,5]
print sum_largest(nums, 4)

#7+7+7+6
>> 27

Permalink: http://problemotd.com/problem/sum-largest/

Comments:

  • Anonymous - 9 years, 6 months ago

    #python
    def sum_largest(listofnums, count):
        return sum(sorted(listofnums)[-count:])
    

    reply permalink

Content curated by @MaxBurstein