Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6381 |

@blackshadows | 6329 |

@mb1973 | 5388 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3357 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@1905439 | 553 |

@terabaap123 | 508 |

@smitadiwedi1991 | 279 |

@DevanandJayakumar | 250 |

@atishagusain | 244 |

@gupta_10 | 226 |

@nipun edara | 224 |

@shubhamkhullar7 | 224 |

@sharmachandan487 | 204 |

@balunagar | 204 |

@arshjit_singh7 | 190 |

Complete Leaderboard |

Given two integers N, M and a 2D matrix Mat of dimensions NxM, the task is to find the maximum sum of

an hourglass.

An hourglass is made of 7 cells in the following form.

A B C

D

E F G

**Example 1:**

**Input:**
N=3,M=3
Mat=[[1,2,3],[4,5,6],[7,8,9]]
**Output:**
35
**Explanation:**
There is only one hour glass which is
1 2 3
5
7 8 9 and its sum is 35.

**Example 2:**

**Input:**
N=2,M=3
Mat=[[1,2,3],[4,5,6]]
**Output:**
-1
**Explanation:**
There are no hour glasses in this matrix.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **findMaxSum()** which takes the two integers N, M, and the 2D matrix Mat as input parameters and returns the maximum sum of an hourglass in the matrix. If there are no hourglasses, it returns -1.

**Expected Time Complexity:**O(N*M)

**Expected Auxillary Space:**O(1)

**Constraints:**

1<=N,M,Mat[i][j]<=1000

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Maximum sum of hour glass

...