#3684
Maximize Sum of At Most K Distinct Elements
easy · 76.7% accepted · 53 likes · top 88%
array · hash table · greedy · sorting
Description
You are given a positive integer array nums and an integer k.
Choose at most k elements from nums so that their sum is maximized. However, the chosen numbers must be distinct.
Return an array containing the chosen numbers in strictly descending order.
Solution