#3478
Choose K Elements With Maximum Sum
expert · 1090 · lc medium +32 · 33.3% accepted · 178 likes · top 11%
Description
Given arrays nums1 and nums2 (both length n) and integer k, build result array answer where for each index i:
- Identify all indices j with nums1[j] < nums1[i].
- From those indices, pick at most k values in nums2 to maximize their sum.
- Store that maximum sum as answer[i].
Return answer.
Code
1
2
3