Skip to content

Instantly share code, notes, and snippets.

@kartikkukreja
Last active July 11, 2017 00:42
Show Gist options
  • Save kartikkukreja/08fb88a4c55d05a81d37 to your computer and use it in GitHub Desktop.
Save kartikkukreja/08fb88a4c55d05a81d37 to your computer and use it in GitHub Desktop.
Minimum Subarray Problem
let A be the given array of integers
let minSum = infinity, minLeft = 0, minRight = 0, currentMin = 0, left = 0, right = 0
for i = 0 to A.length - 1
currentMin += A[i]
if currentMin < minSum
minSum = currentMin
right = i;
minLeft = left
minRight = right
if currentMin > 0
currentMin = 0
left = i + 1
right = i + 1
A[minLeft...minRight] is the minimum sum contiguous subarray.
return minSum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment