Reported September 2026
Amazonheap priority queue

Select K Paired Indices for Maximum Score

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this Amazon OA, reported in September 2026, is trying to pick the best k values from the first array and only then checking the minimum from the second. That order doesn't work, because the minimum changes what's worth picking. This is the classic sort plus min-heap setup. You choose exactly k shared indices, and your score is the sum of first[i] times the smallest second[i] you chose. With n up to 100000, brute force is dead on arrival. If you blank on the sweep order, StealthCoder is the safety net running invisibly during the live assessment.

The problem

Select exactly k shared indices from two equal-length arrays. The score is the sum of selected values from first multiplied by the minimum selected value from second.
Return the maximum score.

Function
maximumPairedScore(first: int[], second: int[], k: int) → int

Examples
Example 1
first = [1,3,3,2]
second = [2,1,3,4]
k = 3
return = 12
Case 1 exercises the documented deterministic contract.
Example 2
first = [4,2,3,1,1]
second = [7,5,10,9,6]
k = 1
return = 30
Case 2 exercises the documented deterministic contract.
Example 3
first = [2,1,14,12]
second = [11,7,13,6]
k = 3
return = 168
Case 3 exercises the documented deterministic contract.

Constraints
1 <= k <= first.length == second.length <= 100000.
All values are positive integers.
The answer fits a signed 32-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to fix the minimum. Sort indices by second in descending order. Walk through them, treating the current second value as the minimum of your selection, since everything processed before it is at least as large. Keep a min-heap of first values with a running sum. Push the current first value, and if the heap exceeds k, pop the smallest and subtract it. Once the heap holds exactly k items, compute sum times current second and track the max. The pitfall is greedy on first alone, or forgetting that the heap must be exactly size k before scoring. Check example 1: sorted by second gives pairs (3,4),(3,3),(3,... ) and the best is 12. Use a 64-bit sum internally even though the answer fits 32 bits, then return it. If the heap logic slips under pressure, StealthCoder can hand you the working version live.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Select K Paired Indices for Maximum Score cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as maximum subsequence score. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Select K Paired Indices for Maximum Score FAQ

What's the trick for Select K Paired Indices for Maximum Score?+

Sort pairs by the second array descending so the current second value is always the minimum of your chosen set. Keep a min-heap of the k largest first values seen so far with a running sum. Score is sum times the current second value.

Why doesn't picking the k largest first values work?+

Because the score multiplies by the minimum of second across your picks. A huge first value paired with a tiny second value can drag the whole product down. You have to trade off both arrays, which is why you fix the minimum and optimize the sum under it.

What's the time complexity I should aim for?+

O(n log n). Sorting costs n log n, and each heap push or pop is log k across n items. With n up to 100000, anything quadratic will time out, so don't try nested loops over index choices.

When do I compute the score in the loop?+

Only when the heap holds exactly k elements. Before that you don't have a valid selection. After pushing and trimming to k, multiply the running sum by the current second value and update your max.

How do I prepare for this in 48 hours?+

Practice the sort-by-one-array, heap-on-the-other pattern until you can write it from memory. Trace example 1 by hand and test k=1 and k=n edge cases. Watch for integer overflow in the sum and use a 64-bit type.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it