Maximum Subsequence Score

Medium Topics Company Tags

Choose exactly k different indices from the two equal-length arrays. The score of your choice is the sum of the selected nums1 values multiplied by the smallest selected nums2 value. Return the largest possible score.

Use the same indices in both arrays. Selected indices do not need to be consecutive, and repeated values at different indices may both be selected.

Scores can exceed the range of a 32-bit signed integer.

Example 1:

Input: nums1 = [5,2,4]
nums2 = [3,9,6]
k = 2

Output: 36

Explanation: Choose indices 1 and 2. The selected nums1 values sum to 6, and the smaller selected nums2 value is 6, giving 36. The other two possible pairs score 21 and 27.

Example 2:

Input: nums1 = [0,7,3]
nums2 = [8,0,4]
k = 1

Output: 12

Explanation: Choosing index 2 gives 3 times 4, or 12. Index 0 gives 0 times 8, and index 1 gives 7 times 0, so neither improves the score.

Example 3:

Input: nums1 = [2,5,1]
nums2 = [7,3,9]
k = 3

Output: 24

Explanation: All three indices must be chosen. Their nums1 values sum to 8, and the minimum nums2 value is 3, so the score is 24.

Constraints:

  • nums1.length == nums2.length == n
  • 1 <= n <= 100000
  • 0 <= nums1[i], nums2[i] <= 100000
  • 1 <= k <= n


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.