Tap here to switch tabs
Problem
Submissions

Problem: Maximize Sum of At Most K Distinct Elements

Maximize Sum of At Most K Distinct Elements asks you to choose up to k different values from an integer array, maximize their total, and return them in strictly descending order.

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

Maximize Sum of At Most K Distinct Elements asks you to choose up to k different values from an integer array, maximize their total, and return them in strictly descending order.

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