Skip to content

Commit 3bd0699

Browse files
author
Chhavi Bansal
committedOct 2, 2022
[2428] Maximise Hour glass sum
1 parent 22be427 commit 3bd0699

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed
 

‎LeetcodeProblems/Algorithms/2428.Hour_Glass_Sum.js ‎LeetcodeProblems/Algorithms/Maximise_Hour_Glass_Sum.js

+15
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,28 @@
33
44
You are given an m x n integer matrix grid.
55
We define an hourglass as a part of the matrix with the following form:
6+
For Input : [[6,2,1],[4,2,1],[9,2,8]]
7+
The Hourglass sum would be => 6 + 2 + 1 + 2( 2nd row , 2nd column) + 9 + 2 + 8
8+
69
Return the maximum sum of the elements of an hourglass.
710
811
Note that an hourglass cannot be rotated and must be entirely contained within the matrix.
12+
13+
Constraints:
14+
15+
m == grid.length
16+
n == grid[i].length
17+
3 <= m, n <= 150
18+
0 <= grid[i][j] <= 106
19+
920
Input: grid = [[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]]
1021
Output: 30
22+
Explanation: The cells shown above represent the hourglass with the maximum sum: 6 + 2 + 1 + 2 + 9 + 2 + 8 = 30.
1123
1224
25+
Input: grid = [[1,2,3],[4,5,6],[7,8,9]]
26+
Output: 35
27+
Explanation: There is only one hourglass in the matrix, with the sum: 1 + 2 + 3 + 5 + 7 + 8 + 9 = 35.
1328
*/
1429

1530
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const assert = require('assert');
2+
const maxSum = require('../../LeetcodeProblems/Algorithms/Maximise_Hour_Glass_Sum').maxSum;
3+
4+
function test() {
5+
assert.equal(maxSum([[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]]));
6+
assert.equal(maxSum([[1,2,3],[4,5,6],[7,8,9]]));
7+
}
8+
9+
module.exports.test = test

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ To run a specific problem in your console run `node <problem_file_path>` (e.g.
7979
| [Permutations With Duplicates ](/LeetcodeProblems/Algorithms/Permutations_With_Duplicates.js) | | |
8080
| [Deletion Distance](/LeetcodeProblems/Algorithms/Deletion_Distance.js) | | |
8181
| [Award Budget Cuts](/LeetcodeProblems/Algorithms/Award_Budget_Cuts.js) | | |
82-
82+
| [Maximum Sum of an Hourglass](/LeetcodeProblems/Algorithms/Maximise_Hour_Glass_Sum.js) | Medium | https://leetcode.com/problems/maximum-sum-of-an-hourglass/ |
8383
### Sorting Algorithms
8484
| Algoritmhs |
8585
| - |

0 commit comments

Comments
 (0)