FastPrepMaximum Subarray Sum
Problems/Maximum Subarray Sum

Maximum Subarray Sum

Mygate logoMygate● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Mygate phone screen for a full-time role. The report names maximum subarray sum and says negative numbers are included. It leaves out edge cases and limits. Here the array and the subarray are nonempty, and the sum is a 64-bit number.

Our version is about 90% the same as the reported question.

Given a nonempty integer array nums, return the largest sum of any nonempty contiguous subarray.

A subarray consists of consecutive elements. Values may be negative. Return the sum, rather than the subarray indices.

Function

maximumSubarraySum(nums: int[]) → long

Examples

Example 1

nums = [-2,1,-3,4,-1,2,1,-5,4]return = 6

The subarray [4, -1, 2, 1] has sum 6, the maximum.

Example 2

nums = [-8,-3,-6]return = -3

The nonempty subarray [-3] is optimal; an empty subarray is not allowed.

Example 3

nums = [5]return = 5

The only nonempty subarray contains 5.

Constraints

  • 1 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • The answer fits a signed 64-bit integer.

More Mygate Phone Screen questions

  • Employees Earning More Than Their ManagerPHONE SCREEN · Seen Sep 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Sep 2026
  • Users Active in Both January and FebruaryPHONE SCREEN · Seen Sep 2026
  • Elements Occurring More Than n/3 TimesPHONE SCREEN · Seen Jan 2025
  • Frog Jump: Minimum EnergyPHONE SCREEN · Seen Jan 2025
  • Left View of a Binary TreePHONE SCREEN · Seen Jan 2025
  • Two SumPHONE SCREEN · Seen Aug 2024
  • Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Jul 2024
  • Minimum Subarray SumPHONE SCREEN · Seen Sep 2023
  • Remove the Nth Node from the EndPHONE SCREEN · Seen Sep 2023

Similar questions at other companies

  • Maximum Subarray Sum with One DeletionServiceNow · PHONE SCREENServiceNow interview questions
  • Maximum Product of a Contiguous SubarrayLinkedIn · PHONE SCREENLinkedIn interview questions
  • Fewest Coins CombinationBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
  • Jump GamePaytm · PHONE SCREENPaytm interview questions
  • Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
  • House RobberVisa · PHONE SCREENVisa interview questions
  • Best Improvement Period of at Least K IntervalsAmazon · PHONE SCREEN
  • Longest Increasing SubsequenceAngel One · PHONE SCREEN
  • Match Shops and BuyersGoogle · PHONE SCREENGoogle interview questions
All Mygate interview questionsSee Mygate hiring insights
Saved
class Solution {
    public long maximumSubarraySum(int[] nums) {
        // write your code here
    }
}
Checking account…