Skip to content

Commit a3fa5fc

Browse files
committed
refactor(searches): scope validation to rectangular matrices per review
1 parent e638b42 commit a3fa5fc

2 files changed

Lines changed: 4 additions & 13 deletions

File tree

‎src/main/java/com/thealgorithms/searches/RowColumnWiseSorted2dArrayBinarySearch.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ public static <T extends Comparable<T>> int[] search(T[][] matrix, T target) {
3636
int colPointer = matrix[0].length - 1; // The pointer at end column
3737

3838
while (rowPointer < matrix.length && colPointer >= 0) {
39-
if (matrix[rowPointer] == null || colPointer >= matrix[rowPointer].length) {
40-
rowPointer++;
41-
continue;
42-
}
43-
4439
int comp = target.compareTo(matrix[rowPointer][colPointer]);
4540

4641
if (comp == 0) {

‎src/test/java/com/thealgorithms/searches/RowColumnWiseSorted2dArrayBinarySearchTest.java‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,10 @@ public void testNullTargetReturnsNotFound() {
273273
}
274274

275275
@Test
276-
public void testMatrixWithNullRow() {
277-
Integer[][] matrix = {
278-
{10, 20, 30},
279-
null,
280-
{18, 28, 38},
281-
};
282-
int[] ans = RowColumnWiseSorted2dArrayBinarySearch.search(matrix, 28);
283-
int[] expected = {2, 1};
276+
public void testNullFirstRowReturnsNotFound() {
277+
Integer[][] matrix = {null};
278+
int[] ans = RowColumnWiseSorted2dArrayBinarySearch.search(matrix, 5);
279+
int[] expected = {-1, -1};
284280
assertEquals(expected[0], ans[0]);
285281
assertEquals(expected[1], ans[1]);
286282
}

0 commit comments

Comments
 (0)