#3684

Maximize Sum of At Most K Distinct Elements

newbie · 225 · lc easy +17 · 76.7% accepted · 53 likes · top 88%

Description

Given a positive integer array nums and integer k, select at most k elements such that all chosen values are distinct and their sum is maximized. Return the chosen elements sorted in strictly descending order.

Code

1
2
3