Last active
July 11, 2017 00:42
-
-
Save kartikkukreja/08fb88a4c55d05a81d37 to your computer and use it in GitHub Desktop.
Minimum Subarray Problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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