if a 2d matrix is given than how to find a submatrix with a max sum from the 2d matrix the submatrix should only contains the index and its surrounding element
7 0 4
0 8 3
12 6 0
ex in this for 8 sum is (7+0+4+0+3+0+6+12)
for 7 it is(0+8+0)
Please give a efficient algo not brute force
@guptanikhil898 for each i,j you just have to sum i-1,j i-1,j-1 i,j-1 and same for plus . also while calculating them check if the idx exists or not if yes then only add it in the sum.
i hope its clear if yes don’t forget to mark resolved and hit like 
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.