Practice Largest Values From Labels
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Choose a subset of items, where item i has values[i] and labels[i]. Select at most numWanted items in total and at most useLimit items sharing any one label. Return the largest possible sum of selected values.
Source: Largest Values From Labels on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
values = [5,4,3,2,1], labels = [1,1,2,2,3], numWanted = 3, useLimit = 1
Output
9
# Example 2
Input
values = [5,4,3,2,1], labels = [1,3,3,3,2], numWanted = 3, useLimit = 2
Output
12
# Example 3
Input
values = [9,8,8,7,6], labels = [0,0,0,1,1], numWanted = 3, useLimit = 1
Output
16
Constraints
n == values.length == labels.length
1 <= n <= 2 * 10^4
0 <= values[i], labels[i] <= 2 * 10^4
1 <= numWanted, useLimit <= n
Related LeetCode Problems
Practice more problems similar to Largest Values From Labels.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.