Skip to content

Commit 1225e57

Browse files
author
Gonzalo Diaz
committed
[Hacker Rank] Interview Preparation Kit: Array: 2D Array - DS. Better test cases.
1 parent d537f6b commit 1225e57

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

src/algorithm_exercises_csharp/hackerrank/interview_preparation_kit/arrays/TwoDArray.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ private static List<int> getHourGlass(List<List<int>> arr, int positionX, int po
3131

3232
public static int hourglassSum(List<List<int>> arr)
3333
{
34-
int matrixSize = 0;
35-
36-
if (arr.Count > 0)
37-
{
38-
matrixSize = arr.Count;
39-
}
34+
int matrixSize = arr.Count;
4035

4136
int matrixStartIndex = 1;
4237
int matrixEndIndex = matrixSize - 2;

src/algorithm_exercises_csharp_test/Resources/hackerrank/interview_preparation_kit/arrays/2d_array.testcases.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,29 @@
1010
[0, 0, 1, 2, 4, 0]
1111
],
1212
"expected": 19
13+
},
14+
{
15+
"title": "Sample Test Case 1",
16+
"input": [
17+
[1, 1, 1, 0, 0, 0],
18+
[0, 1, 0, 0, 0, 0],
19+
[1, 1, 1, 0, 0, 0],
20+
[0, 9, 2, -4, -4, 0],
21+
[0, 0, 0, -2, 0, 0],
22+
[0, 0, -1, -2, -4, 0]
23+
],
24+
"expected": 13
25+
},
26+
{
27+
"title": "Sample Test Case 2",
28+
"input": [
29+
[-9, -9, -9, 1, 1, 1],
30+
[0, -9, 0, 4, 3, 2],
31+
[-9, -9, -9, 1, 2, 3],
32+
[0, 0, 8, 6, 6, 0],
33+
[0, 0, 0, -2, 0, 0],
34+
[0, 0, 1, 2, 4, 0]
35+
],
36+
"expected": 28
1337
}
1438
]

src/algorithm_exercises_csharp_test/hackerrank/interview_preparation_kit/arrays/TwoDArray.Test.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,16 @@ public void testHourglassSum()
3333
Assert.AreEqual(test.expected, result);
3434
}
3535
}
36+
37+
38+
[TestMethod]
39+
public void testHourglassSumEdgeCases()
40+
{
41+
List<List<int>> input = [];
42+
int expected = 0;
43+
int result = TwoDArray.hourglassSum(input);
44+
45+
Assert.AreEqual(expected, result);
46+
}
3647
}
3748

0 commit comments

Comments
 (0)