DP(Top Down approach) || Comments-added
\nint countSquares(vector<vector<int>>& matrix) {\n        int rows = matrix.size();\n        int cols = matrix[0].size();\n        int count = 0;\n        for(
```\nint countSquares(vector<vector<int>>& matrix) {\n        int rows = matrix.size();\n        int cols = matrix[0].size();\n        int count = 0;\n        for(int i=0; i<rows; i++){\n            for(int j=0; j<cols; j++){\n                if(matrix[i][j] == 0)// if 0 it is of no use\n                    continue;\n                else if(i>0 && j>0){ // increment size of sq. matrix by 1 of minimum of its neighbour \n                    matrix[i][j] = 1 + min({matrix[i-1][j-1], matrix[i-1][j], matrix[i][j-1]});\n                }\n                count += matrix[i][j];// counting total sq matrix\n                // cout<<matrix[i][j]<<" ";\n            }\n            // cout<<endl;\n        }\n        return count;\n    }\n```\n\n**Please Do UpVote**
['Dynamic Programming', 'C', 'C++']