Created
September 14, 2016 04:07
-
-
Save michaellandi/cd39ceba3fdb76b9e2194b1252b4bc65 to your computer and use it in GitHub Desktop.
Bruteforce Largest Subarray o(n^3)
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
function findLargestSubarray(arr) { | |
var max = 0; | |
var start, end; | |
for (var i = 0; i < arr.length; i++) | |
for (var j = i; j < arr.length; j++) | |
{ | |
var current = 0; | |
for (var k = i; k <= j; k++) | |
current += arr[k]; | |
if (current > max) | |
{ | |
start = i; | |
end = j; | |
max = current; | |
} | |
} | |
return { start: start, end: end }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment