1090. Largest Values From Labels
https://leetcode.com/problems/largest-values-from-labels
Description
There is a set of n
items. You are given two integer arrays values
and labels
where the value and the label of the ith
element are values[i]
and labels[i]
respectively. You are also given two integers numWanted
and useLimit
.
Choose a subset s
of the n
elements such that:
The size of the subset
s
is less than or equal tonumWanted
.There are at most
useLimit
items with the same label ins
.
The score of a subset is the sum of the values in the subset.
Return the maximum score of a subset s
.
Example 1:
Example 2:
Example 3:
Example 4:
Constraints:
n == values.length == labels.length
1 <= n <= 2 * 104
0 <= values[i], labels[i] <= 2 * 104
1 <= numWanted, useLimit <= n
ac
Last updated