Maximum Sum of a Contiguous Subarray
Updated
Problem statement
Given an integer array nums, return the largest sum of any nonempty contiguous subarray. A contiguous subarray uses every element from one chosen start position through one chosen end position.
Return only the maximum value. Different subarrays may attain it. A singleton is allowed; choosing no elements is not. Do not change the input.
Function
maximumSubarraySum(nums: int[]) → intExamples
Example 1
nums = [3,-4,6,-1,2,-7]return = 7The contiguous block [6,-1,2] has sum 7, which is larger than the sum of every other contiguous block.
Example 2
nums = [-8,-3,-6]return = -3A nonempty block is required. The singleton [-3] has the largest sum; choosing no elements is not allowed.
Example 3
nums = [5]return = 5The only nonempty block contains 5 and has sum 5.
Constraints
- For this exercise, assume
1 <= nums.length <= 1000. - For this exercise, assume
-1000000 <= nums[i] <= 1000000.
More LinkedIn Phone Screen questions
- Total Years of Work ExperiencePHONE SCREEN · Seen Nov 2026
- Sum an Arbitrary-Dimensional ArrayPHONE SCREEN · Seen Oct 2026
- Known Words Matching Phone DigitsPHONE SCREEN · Seen Oct 2026
- Inverse-Depth Nested List SumPHONE SCREEN · Seen Oct 2026
- Valid Number with ExponentsPHONE SCREEN · Seen Oct 2026
- Maximum Product of a Contiguous SubarrayPHONE SCREEN · Seen Oct 2026
- Sort a Quadratic-Transformed ArrayPHONE SCREEN · Seen Oct 2026
- Constant-Time Minimum StackPHONE SCREEN · Seen Oct 2026
- Randomized String MultisetPHONE SCREEN · Seen Oct 2026
- Move the Nth Linked-List Node to the FrontPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- 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
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
- Minimum-Cost Color SequenceOpenAI · OA · PHONE SCREENOpenAI interview questions