Skip to content

Resource · Guide or article

Maximum subarray problem

Maximum subarray, finding the contiguous run with the largest sum, with pointers to brute-force, divide and conquer, and DP solutions.

Reviewed

Open the original: Maximum subarray problem (opens the original site in a new tab)

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

The maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array, a[1...n], of numbers which has the largest sum, where, The list usually contains both positive and negative numbers along with 0. For example, for the array of values −2, 1, −3, 4, −1, 2, 1, −5, 4 the contiguous subarray with the largest sum is 4, −1, 2, 1, with sum 6.

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Reference

What it covers

  • Example array with answer 4, -1, 2, 1 summing to 6.
  • Solutions section listing the folder's JavaScript files with stated complexities: brute force O(n^2), divide and conquer O(n^2), dynamic programming O(n).

How to use it

PrepKit study advice, not a claim made by the source.

Write the O(n) pass yourself first, test it on an all-negative array, then compare with dpMaximumSubarray.js.

Scope and limitations

The README does not explain how any solution works; you must read the code or the external links (Wikipedia, YouTube, GeeksForGeeks, LeetCode). Code is JavaScript only.

Access and format

English README on GitHub alongside JavaScript source; trekhleb/javascript-algorithms, MIT license, free.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/sets/maximum-subarray/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email