Tap here to switch tabs
Problem
Submissions

Problem: Maximize Sum of At Most K Distinct Elements

med
30 min
Try to solve the Maximize Sum of At Most K Distinct Elements problem.

Statement

You are given an integer array nums and an integer k.

Choose at most k distinct elements from nums such that their sum is maximized.

Return an array containing the selected elements sorted in strictly descending order.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq k ≤\leq nums.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize Sum of At Most K Distinct Elements

med
30 min
Try to solve the Maximize Sum of At Most K Distinct Elements problem.

Statement

You are given an integer array nums and an integer k.

Choose at most k distinct elements from nums such that their sum is maximized.

Return an array containing the selected elements sorted in strictly descending order.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 1≤1 \leq k ≤\leq nums.length