Maximum Subarray Problem
Maximum Subarray Problem — ExecCode Easy DSA Practice
Solve the Maximum Subarray problem on ExecCode. Free online easy DSA practice in DP. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an integer array nums, find the subarray with the largest sum, and return its sum. A subarray is a contiguous non-empty sequence of elements within an array.
Examples
Input nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4]; Output 6. Input nums = [-8, -3, -6, -2, -5, -4]; Output -2. Input nums = [5, 4, -1, 7, 8]; Output 23
Constraints
1 ≤ nums.length ≤ 10⁵ -10⁴ ≤ nums[i] ≤ 10⁴
Practice Maximum Subarray free on ExecCode. Browse DSA problems, topic map, and placement guides.