FastPrepMaximum Sum of Two Non-Overlapping Subarrays
Problems/Maximum Sum of Two Non-Overlapping Subarrays

Maximum Sum of Two Non-Overlapping Subarrays

Google logoGoogle● MediumFULLTIMEPHONE SCREEN

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Google SWE candidate interviewing for ML teams reports a phone-screen task similar to the linked Maximum Sum of Two Non-Overlapping Subarrays problem. This practice uses the public linked task and its bounds; the report does not state any interviewer-specific variation. Source match is about 90%.

Given an array nums of nonnegative integers and two lengths firstLen and secondLen, choose two non-overlapping contiguous subarrays of those exact lengths. Return the largest possible sum of all elements in the two chosen subarrays.

The subarray of length firstLen may occur before or after the subarray of length secondLen. The two subarrays may touch at a boundary but must not share an index.

Function

maxSumTwoNoOverlap(nums: int[], firstLen: int, secondLen: int) → int

Examples

Example 1

nums = [0,6,5,2,2,5,1,9,4]firstLen = 1secondLen = 2return = 20

Choose [9] and [6,5]; their sums add to 20.

Example 2

nums = [3,8,1,3,2,1,8,9,0]firstLen = 3secondLen = 2return = 29

Choose the length-three subarray [3,8,1] and the length-two subarray [8,9]. Their sums are 12 and 17.

Example 3

nums = [2,1,5,6,0,9,5,0,3,8]firstLen = 4secondLen = 3return = 31

The disjoint windows [5,6,0,9] and [0,3,8] sum to 20 + 11 = 31.

Constraints

  • 1 <= firstLen, secondLen <= 1000.
  • firstLen + secondLen <= nums.length <= 1000.
  • 0 <= nums[i] <= 1000.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Maximum Value for Two Delivery RobotsNuro · PHONE SCREENNuro interview questions
  • Longest Run of Ones After Flipping k ZerosC3.ai · PHONE SCREENC3.ai interview questions
  • Profit AnalysisVirtu Financial · OAVirtu Financial interview questions
  • Minimum Size Subarray SumMicrosoft · OAMicrosoft interview questions
  • Subarray with a Given SumExpedia · ONSITE INTERVIEWExpedia interview questions
  • Shortest Subarray with Sum at Least KOracle · ONSITE INTERVIEWOracle interview questions
  • Threshold AlertsGoldman Sachs · OAGoldman Sachs interview questions
  • Reduce Memory UsageAmazon · OA
  • Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
  • Subarray Product Less Than KApple · PHONE SCREENApple interview questions

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
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int maxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen) {
        // Write your code here
    }
}
Checking account…