I read Evgeny Kluev answer on this and was not able to understand the mechanism. Now let us understand using an example. let us say we have this matrix. [1  2  3  2   5, 2  4  6  4  10, 3  6  9  6  15, 2  4  6  4  10, 5  10 15 10 25]Now applying step 1 we get . [ 1  2  3  2  5 ,  3  6  9  6  15,  6  12 18 12 30,  8  16 24 16 40,  13 26 39 26 65] Now applying step 2 we get all the possible pair of row indices i.e.  (1,2) (1,3) (1,4) (1,5) (2,3) (2,4) (2,5) (3,4) (3,5) (4,5)Now comes the last part of applying two pointer algorithm. Which i am failing to understand.For ex. Lets take (1,2) B[2][1] - B[1][1]= 3-1 = 2B[2][2] - B[1][2]= 6-2 = 4 B[2][3] - B[1][3]= 9-3 = 6 B[2][4] - B[1][4]= 6-2 = 4B[2][5] - B[1][5]= 15-5 =10Now how is that helping? I mean on these values if we apply two pointer algorithm what will we achieve? For example i am looking for all occurrences of 36. How do i get close to it. ? Can anybody carry this forward and explain the solution?
Number of submatrices with a particular sum- Answer Explantion
algorithms;matrices