diff --git a/Maximum sum of hour glass in matrix.cpp b/Maximum sum of hour glass in matrix.cpp new file mode 100644 index 00000000..5ed96a4d --- /dev/null +++ b/Maximum sum of hour glass in matrix.cpp @@ -0,0 +1,48 @@ +#include +using namespace std; +const int R = 5; +const int C = 5; + +// Returns maximum sum of hour glass in ar[][] +int findMaxSum(int mat[R][C]) +{ + if (R<3 || C<3) + return -1; + + // Here loop runs (R-2)*(C-2) times considering + // different top left cells of hour glasses. + int max_sum = INT_MIN; + for (int i=0; i