FastPrepMaximum Subarray Endpoint Score
Problems/Maximum Subarray Endpoint Score

Maximum Subarray Endpoint Score

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Interview reports describe a score of the endpoints minus the interior, and one reported example is included. We added the input limits and more examples. Our version is about 97% the same as the reported questions.

Special thanks: 🌷 A special thank you to a lovely, amazing fren who shared that this question appeared again on November 4, 2026! (˶˃ ᵕ ˂˶) .ᐟ.ᐟ 💚

You are given an integer array nums, which may contain negative values.

Choose a section of consecutive elements nums[i..j] containing at least two elements, so i < j. Its score is the sum of its two endpoint values minus the sum of all values strictly between them:

score(i,j) = nums[i] + nums[j] - sum(nums[i+1..j-1]).

The interior of a two-element subarray is empty and has sum 0. A one-element subarray is invalid.

Return the maximum score over all valid subarrays as a signed 64-bit integer.

Use O(n) time and O(1) auxiliary space, where n = nums.length.

Function

maximumEndpointScore(nums: int[]) → long

Examples

Example 1

nums = [5,-100,5]return = 110

The full array scores 5 + 5 - (-100) = 110. Either adjacent pair scores -95.

Example 2

nums = [4,1,7,3]return = 10

The adjacent pair [7,3] scores 10. The interval [4,1,7] also scores 4 + 7 - 1 = 10, and no interval has a higher score.

Example 3

nums = [-5,-2]return = -7

The only legal subarray contains both elements. Its interior is empty, so its score is -5 + -2 = -7; a singleton is not allowed.

Example 4

nums = [3,1,2,4,5]return = 9

The adjacent subarray [4,5] has an empty interior and scores 4 + 5 = 9, the maximum. For comparison, [3,1,2,4] scores 3 + 4 - (1 + 2) = 4.

Constraints

  • 2 <= nums.length <= 200000.
  • -10^9 <= nums[i] <= 10^9.
  • Use signed 64-bit arithmetic for scores and running sums.

More Google Onsite Interview questions

  • 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
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Subarray Sum Equals KServiceNow · ONSITE INTERVIEWServiceNow interview questions
  • Count Subarrays with Equal Even and Odd CountsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Product of Array Except SelfWalmart Labs · ONSITE INTERVIEW
  • Subarrays Whose Sum Is a Power of TwoKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions
  • Count Subarrays with Sum KMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
  • Product Of Array Except SelfInfosys · ONSITE INTERVIEWInfosys interview questions
  • Centered K-by-K Submatrix SumsCitadel · ONSITE INTERVIEWCitadel interview questions
  • Farthest Affordable Shop per QueryAdobe · ONSITE INTERVIEWAdobe interview questions
  • Product of Array Except SelfSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions

Interview reports that mention this question

  • Google FDE and Cloud AI Interviews: 7 Experiences (Part 3 of 3)
  • Google SWE Intern Extra Interview Round: 2 Experiences
  • Google Intern Coding and OOP: 19 Experiences (Part 5 of 8)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long maximumEndpointScore(int[] nums) {
        // Write your code here.
    }
}
Checking account…