Problem · Array

Maximum Subarray Sum

Learn this problem
EasySafe SecurityONSITE INTERVIEW

Problem statement

You are given an integer array nums. Find the contiguous subarray with the largest sum and return that sum.

Function

maxSubArray(nums: int[]) → int

Examples

Example 1

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

The best contiguous subarray is [4,-1,2,1], whose sum is 6.

drafts saved locally
public int maxSubArray(int[] nums) {
  // write your code here
}
nums[-2,1,-3,4,-1,2,1,-5,4]
expected6
checking account