Skip to content

Instantly share code, notes, and snippets.

@thomas4g
Created March 13, 2012 00:41
Show Gist options
  • Save thomas4g/2025777 to your computer and use it in GitHub Desktop.
Save thomas4g/2025777 to your computer and use it in GitHub Desktop.
Four Passes
for(;i<nums.length;i++) {
var northeast = nums[i]*nums[i-(n-1)]*nums[i-2*(n-1)]*nums[i-3*(n-1)],
if(northeast > p) p = northeast;
}
for(;i<nums.length;i++) {
var north = nums[i]*nums[i-n]*nums[i-2*n]*nums[i-3*n];
if(north > p) p = north;
}
for(;i<nums.length;i++) {
var east = nums[i]*nums[i+1]*nums[i+2]*nums[i+3];
if(east > p) p = east;
}
for(;i<nums.length;i++) {
var northeast = nums[i]*nums[i+(n+1)]*nums[i+2*(n+1)]*nums[i+3*(n+1)];
if(southeast > p) p = southeast;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment