Skip to content
Decoder

Maximum Subsequence Score

Medium

Problem

You get two arrays of the same length, nums1 and nums2, and a number k. Choose `k` indices. The score of your choice is

Example 1

(sum of nums1 at the chosen indices) * (minimum of nums2 at the chosen indices)

Return the maximum possible score.

Example 2

Input
nums1 = [1, 3, 3, 2], nums2 = [2, 1, 3, 4], k = 3
Output
12

Choosing indices 0, 2 and 3 gives (1 + 3 + 2) * min(2, 3, 4) = 6 * 2 = 12.

Constraints

  • 1 <= k <= n <= 10^5 (n is the length of both arrays)
  • 0 <= nums1[i], nums2[i] <= 10^5

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.