Skip to content

Instantly share code, notes, and snippets.

@MathisHammel
Created December 19, 2016 01:11
Show Gist options
  • Save MathisHammel/4e10d6f5eefc38f1d7287225415b639b to your computer and use it in GitHub Desktop.
Save MathisHammel/4e10d6f5eefc38f1d7287225415b639b to your computer and use it in GitHub Desktop.
def maxsubarr(arr):
h=len(arr)
w=len(arr[0])
bestsum=arr[0][0]
bestcoords=None
for lbeg in range(h):
for cbeg in range(w):
for lend in range(lbeg,h):
for cend in range(cbeg,h):
subsum=0
for l in range(lbeg,lend+1):
for c in range(cbeg,cend+1):
subsum+=arr[l][c]
if subsum==bestsum:
print "equal",bestsum
if subsum>=bestsum:
bestsum=subsum
bestcoords=((lbeg,cbeg),(lend,cend))
return bestcoords
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment