C++ | O(1) Space DP
Solution: \nLength of the smallest square with side length > 1 = 2 \ne.g.\n\n1 1\n1 1\n\n\nSimply update bottom right value to reflect current area up to that c
Solution: \nLength of the smallest square with side length > 1 = 2 \ne.g.\n```\n1 1\n1 1\n```\n\nSimply update bottom right value to reflect current area up to that cell by taking min of upperleft, upper and left + 1. Min will exclude incomplete squares where one value = 0.\n```\n1 1\n1 2\n```\n\nIn square length of 3, same situation occurs\n```\n1 1 1         1 1 1\n1 1 1   =>    1 2 2(both upper && upperleft == 1 here so thats why this is 2 and not 3) \n1 1 1         1 2 3(min of surrounding values == 2 so value here is 3)\n```\n\n```\nclass Solution {\npublic:\n    int countSquares(vector<vector<int>>& matrix) {\n        int m = matrix.size(), n = matrix[0].size();\n        int count = 0;\n        \n        for(int i = 0; i < m; ++i) {\n            for(int j = 0; j < n; ++j) {\n                if(matrix[i][j] == 1) {\n                    int upperleft   = i > 0 && j > 0 ? matrix[i - 1][j - 1] : 0;\n                    int upper       = i > 0 ? matrix[i - 1][j] : 0;\n                    int left        = j > 0 ? matrix[i][j - 1] : 0;\n                    \n                    matrix[i][j] = min({ upperleft, upper, left }) + 1;\n                    \n                    count += matrix[i][j];\n                }\n            }\n        }\n        \n        return count;\n    }\n};\n```
['Dynamic Programming', 'C']