Reported August 2026
Googlemath

Maximize Two Endpoint Values

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

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

Google's August 2026 report of this OA has a trap that looks like a range-sum problem and isn't. The score formula is dressed up with prefix sums and interior subtraction, but it collapses to values[i] + values[j]. If you're taking this assessment in the next day or two, the edge case that breaks a naive solution is all-negative input, where people seed their max with 0 and return the wrong answer. StealthCoder sits invisibly as a safety net if you blank mid-assessment, but this one is easy once you see the cancellation.

The problem

You are given an integer array values. Choose two indices i and j with i < j.
The score of the chosen pair is
sum(values[i..j]) - sum(values[i+1..j-1]),
where the sum of an empty interior range is 0.
Return the maximum score over all valid pairs. The result is a 64-bit integer.

Function
maximumEndpointSum(values: int[]) → long

Examples
Example 1
values = [4,1,7,3]
return = 11
Choose the endpoints with values 4 and 7. Interior values cancel from the two range sums, so the score is 4 + 7 = 11.
Example 2
values = [-5,-2,-8]
return = -7
The two largest values are -2 and -5, producing the maximum score -7.
Example 3
values = [6,6]
return = 12
The only pair has no interior values and scores 6 + 6 = 12.

Constraints
2 <= values.length <= 2 * 10^5
-10^9 <= values[i] <= 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

Expand the formula. sum(values[i..j]) includes every element from i to j. Subtracting sum(values[i+1..j-1]) removes everything strictly between them. What's left is values[i] + values[j]. Since i < j is the only constraint, you want the two largest values in the array, regardless of position. Any pair of distinct indices can be ordered so i < j. So sort, or better, scan once tracking the top two. The pitfall is initialization. Seed with 0 and Example 2 returns the wrong answer, because every value is negative. Seed with negative infinity, or take the first two elements. Also use a 64-bit type, since two values of 10^9 sum to 2 * 10^9 and overflow a 32-bit int. If you freeze on the live OA, StealthCoder can hand you the one-pass solution, but you can write it from memory in two minutes.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Maximize Two Endpoint Values 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximize Two Endpoint Values FAQ

What's the trick in Maximize Two Endpoint Values?+

The interior sum cancels out. sum(i..j) minus sum(i+1..j-1) leaves values[i] + values[j]. So the answer is just the sum of the two largest elements in the array. No prefix sums, no nested loops, no dynamic programming needed.

How hard is this one really?+

Easy once you simplify the formula, and Google's August 2026 report suggests the difficulty is the disguise. Candidates who start building prefix sums waste time. Spend the first minute on algebra, then write a ten-line scan.

What edge cases break a naive solution?+

All-negative arrays, like [-5,-2,-8], where initializing the max to 0 gives a wrong answer. Also overflow: two values near 10^9 sum past the 32-bit limit, so use a long. And length exactly 2, where the only pair has no interior.

Do I need to sort the array?+

No. Sorting works in O(n log n) and passes for 2 * 10^5 elements, but a single pass tracking the largest and second largest is O(n) and just as short. Initialize both to the smallest possible long value, then update as you scan.

How do I prepare for this in 48 hours?+

Practice spotting algebraic simplifications before reaching for a data structure. Write the top-two scan from scratch, test it on all-negative input and a two-element array, and confirm your return type is 64-bit. That covers everything this problem can throw at you.

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

OA at Google?
Invisible during screen share
Get it