I have to admit that I've not been able to solve this task and I have downloaded the solution to see the logic of it. I'd my own idea about how to solve it on a paper but I was not able to get it implemented. Said that I'm not sure that the solution given by CODEGYM is right. Here are my doubts. * The first issue is that when arr[i][j] is copied into a[i][j] the limit value of j, shouldn't it be a[0].length? * Then the point 2 of conditions said that the rectangles do not touch or overlap. T Let's imagine that there's a rectangle with the following limits [0,0] [0,2] / [2,0] [2,2]. To me and according to the condition no 1 should be counted from [0,3] to [2,3] and from [2,0] to [3,2]. Am I right? [0,0] [0,1] [0,2] [0,3] [1,0] [1,1] [1,2] [1,3] [2,0] [2,1] 2,2] [2,3] [3,0] [3,1] [3,2] [3,3] * a1 and a2 array are square arrays so the x length and the y length have the same value. Lets try with something like {1, 1, 0, 0, 1, 1}, {1, 1, 0, 1, 0, 0}, {1, 1, 0, 0, 1, 0}, {0, 0, 0, 1, 1, 1}, {1, 1, 0, 1, 1, 0} What should be the result? 6?