Skip to content

Commit 1157b51

Browse files
author
Gonzalo Diaz
committed
[Hacker Rank] Interview Preparation Kit: Array: 2D Array - DS. Solved ✅.
1 parent 41e3dd0 commit 1157b51

File tree

2 files changed

+28
-6
lines changed
  • algorithm-exercises-java/src

2 files changed

+28
-6
lines changed

algorithm-exercises-java/src/main/java/ae/hackerrank/interview_preparation_kit/arrays/TwoDarray.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ private TwoDarray() { }
1616
private static List<Integer> getHourGlass(List<List<Integer>> arr, int positionX, int positionY) {
1717
List<Integer> result = new ArrayList<>();
1818

19-
if (arr == null || arr.isEmpty()) {
20-
return result;
21-
}
22-
2319
// top
2420
result.add(arr.get(positionX - 1).get(positionY - 1));
2521
result.add(arr.get(positionX - 1).get(positionY));

algorithm-exercises-java/src/test/java/ae/hackerrank/interview_preparation_kit/arrays/TwoDarrayTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

55
import java.io.IOException;
6+
import java.util.ArrayList;
67
import java.util.List;
78
import org.junit.jupiter.api.BeforeAll;
89
import org.junit.jupiter.api.Test;
@@ -33,18 +34,43 @@ public void setup() throws IOException {
3334
}
3435

3536

36-
@Test void testArrayManipulation() {
37+
@Test void testHourglassSum() {
3738
for (TwoDarrayTestCase testCase : testCases) {
3839
long solutionFound = TwoDarray.hourglassSum(testCase.input);
3940

4041
assertEquals(testCase.expected, solutionFound,
4142
"%s(%s) answer must be: %s".formatted(
42-
"CrushOptimized.arrayManipulation",
43+
"TwoDarray.hourglassSum",
4344
testCase.input.toString(),
4445
testCase.expected
4546
)
4647
);
4748
}
4849
}
50+
51+
@Test void testHourglassSumEdgeCases() {
52+
List<List<Integer>> input = null;
53+
Integer expected = null;
54+
Integer solutionFound = TwoDarray.hourglassSum(null);
55+
assertEquals(expected, solutionFound,
56+
"%s(%s) answer must be: %s".formatted(
57+
"TwoDarray.hourglassSum",
58+
input,
59+
expected
60+
)
61+
);
62+
63+
input = new ArrayList<List<Integer>>();
64+
expected = null;
65+
solutionFound = TwoDarray.hourglassSum(null);
66+
67+
assertEquals(expected, solutionFound,
68+
"%s(%s) answer must be: %s".formatted(
69+
"TwoDarray.hourglassSum",
70+
input,
71+
expected
72+
)
73+
);
74+
}
4975
}
5076

0 commit comments

Comments
 (0)