FastPrepMaximize Two Endpoint Values
Problems/Maximize Two Endpoint Values

Maximize Two Endpoint Values

Google logoGoogle● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report does not give constraints or the exact output format. Our maximum-value version matches the endpoint-sum goal at about 97%.

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

More Google Onsite Interview questions

  • Minimum Piano Hand Raises and Thumb PositionsONSITE INTERVIEW · Seen Dec 2026
  • Swap Adjacent in LR StringONSITE INTERVIEW · Seen Dec 2026
  • Top Ten Largest FilesPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Count Winning Dice Face PairsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find a Failing Test PairONSITE INTERVIEW · Seen Nov 2026
  • Minimum Cars for Rental RequestsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Squirrel Nut Collection Shortest PathAmazon · ONSITE INTERVIEW
  • Server InvestmentRippling · OARippling interview questions
  • Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
  • Make Layer Times OddPatreon · OAPatreon interview questions
  • Halve Values Until All Are at Most kAdobe · PHONE SCREENAdobe interview questions
  • Delete and Freeze GameRubrik · OARubrik interview questions
  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Minimum Operations to Make Every Array Element OneOtter.ai · PHONE SCREENOtter.ai interview questions

Interview reports that mention this question

  • Google PhD New Grad AI/ML SWE Onsite: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long maximumEndpointSum(int[] values) {
        // Write your code here.
    }
}
Checking account…