About this question

Sum of Top K

Easy · mle_slice · Quant Developer interview question · mle-slice

Given a list of integers nums and an integer k, return the sum of the k largest elements. If k exceeds the length of nums, return the sum of all elements. Example: nums = 1, 2, 3, 4, 5, k = 2 returns 9 (5 + 4).