## Flipkart Interview Question for Software Engineer / Developers

Country: India
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
1
of 1 vote

Check "Dynamic Programming | Set 27 (Maximum sum rectangle in a 2D matrix)" on geeks for geeks site.

Comment hidden because of low score. Click to expand.
0
of 0 vote

convolve the original matrix with the matrix of ones (Kernel) and fing the max value of the 2D matrix. which will return the center position of the submatrix with the largest sum.

Size of the kernal will decide the size of the sunMatrix.
in matlab it can be done like this

``````orignal2DMatrix;
subMatKernal = ones(sizeOfSubMatrix,sizeOfSubMatrix);
result = conv2(orignal2DMatrix,subMatKernal );
matrixIndex= find(max(result));``````

Comment hidden because of low score. Click to expand.
0

Consider that a convolution is of size O(n^2) and therefore contains the sums of only O(n^2) submatrices. However, there are O(n^4) different submatrices, so you're not considering all the possible submatrices.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Logic:

Step 1:
Row wise operation:
Replace the matrix data with the sum of element in row upto current column number.
Replace A[x,y] = A[x,0]+A[x,1]+A[x,2]+A[x,3]+......+A[x,y]
If A =
[1 2 3]
[4 5 6]
[7 8 9]
then after first step:
A=
[1 3 6]
[4 9 15]
[7 15 24]

Step 2:
Column wise operation:
Replace the matrix data with the sum of element in column upto current row number.
Replace A[x,y] = A[0,y]+A[1,y]+A[2,y]+A[3,y]+......+A[x,y]

Now A =
A=
[1 3 6]
[5 12 21]
[12 27 45]

Step 3:
Now find the max diff b/w to A[x,y]-A[x',y'] elements in the result matrix where
X>=X' and
Y>=Y'

Comment hidden because of low score. Click to expand.
0

Comment hidden because of low score. Click to expand.
0
of 0 vote

Way too easy....

ComputeMax(x1,y1,x2,y2) = max(ComputeMax(x1+1,y1,x2,y2),ComputeMax(x1,y1+1,x2,y2),ComputeMax(x1,y1,x2-1,y2),ComputeMax(x1,y1,x2,y2-1), sum of this whole matrix);

You need to use memoization to reduce re-computations.

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.