Maximum Subarray
Updated
Problem statement
Given a non-empty integer array nums, return the maximum possible sum of a non-empty contiguous subarray.
The result is a signed 64-bit integer.
Function
maxSubarraySum(nums: int[]) → longExamples
Example 1
nums = [-2,1,-3,4,-1,2,1,-5,4]return = 6The contiguous subarray [4, -1, 2, 1] has the maximum sum, 6.
Example 2
nums = [-8,-3,-6]return = -3A valid subarray must be non-empty, so the best choice is the single value -3.
Constraints
1 <= nums.length <= 200000-10^9 <= nums[i] <= 10^9
More Google Phone Screen questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE 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
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
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
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN