Skip to content

Commit 41e3dd0

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

File tree

1 file changed

+8
-2
lines changed
  • algorithm-exercises-java/src/main/java/ae/hackerrank/interview_preparation_kit/arrays

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ 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+
1923
// top
2024
result.add(arr.get(positionX - 1).get(positionY - 1));
2125
result.add(arr.get(positionX - 1).get(positionY));
@@ -38,10 +42,12 @@ private static List<Integer> getHourGlass(List<List<Integer>> arr, int positionX
3842
public static Integer hourglassSum(List<List<Integer>> arr) {
3943
int matrixSize = 0;
4044

41-
if (arr != null) {
42-
matrixSize = arr.size();
45+
if (arr == null) {
46+
return null;
4347
}
4448

49+
matrixSize = arr.size();
50+
4551
int matrixStartIndex = 1;
4652
int matrixEndIndex = matrixSize - 2;
4753

0 commit comments

Comments
 (0)