Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
if M is of size nxn (does not have to be a square), this is a question solved in careercup book, brute force is O(n^6), optimized with O(n^4) additional space complexity O(n^2)
Additional space complexity is for precomputing calculating sum till (i,j)
sum[i][j] = sum[i - 1][j] +sum[i][j-1]-sum[i-1][j-1]+M[I,j]
and then selecting different matrices is O(n^4), the sum calculation is O(1)
sum[i2][j2] - sum[i2][j1 - 1] - sum[i1 - 1][j2] + sum[i1 - 1][j1 - 1];
just return max sum
Brainless Urik , sorry, man, this is the best algorithm I have ever known and I cannot prove that this is the optimal one.
we can use kandane's to do so
getMaximumSubMatrixSum is function which needs to be called
- javaD November 03, 2013