Repository navigation
fix(searches): add null safety and empty matrix handling to RowColumnWiseSorted2dArrayBinarySearch - #7725
Conversation
…WiseSorted2dArrayBinarySearch
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Hi @DenizAltunkapan, Could you please review this pull request when you have a moment? Summary of Changes
Test Results
Thank you for your time and consideration! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7725 +/- ##
============================================
+ Coverage 82.23% 82.28% +0.05%
- Complexity 8402 8418 +16
============================================
Files 843 843
Lines 26140 26148 +8
Branches 5100 5103 +3
============================================
+ Hits 21495 21516 +21
+ Misses 3853 3840 -13
Partials 792 792 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| if (matrix[rowPointer] == null || colPointer >= matrix[rowPointer].length) { | ||
| rowPointer++; | ||
| continue; |
There was a problem hiding this comment.
@hardikkaurani please check this
The null and empty input handling is a useful improvement. However, we found a correctness issue with the newly added support for jagged arrays.
Consider the following example:
Integer[][] matrix = {
{1, 4, 7},
{5}
};Searching for 5 returns {-1, -1} instead of {1, 0} because the new bounds check skips the second row entirely when colPointer exceeds its length.
The current staircase search algorithm assumes a rectangular matrix with rows and columns sorted in ascending order. Supporting jagged arrays requires additional consideration to preserve correctness.
I would suggest keeping this PR focused on null and empty input validation for rectangular matrices, rather than introducing partial support for jagged arrays.
Please also add a regression test for the case above if jagged arrays are intended to be supported.
Thanks!
There was a problem hiding this comment.
Agreed just making some changes !
There was a problem hiding this comment.
Updated as suggested! Removed the partial jagged array checks to keep the implementation strictly focused on null and empty input validation for rectangular matrices, and replaced the jagged test with a null-first-row boundary test ({null}).
|
Hi @DenizAltunkapan, I have updated the PR following your feedback:
Please let me know if everything looks good or if any further adjustments are needed. Thank you! |

clang-format -i --style=file path/to/your/file.javaDescription
This pull request adds null safety, empty matrix handling, and marks
RowColumnWiseSorted2dArrayBinarySearchfinal:matrix == null, empty 2D array (matrix.length == 0), empty first row (matrix[0].length == 0), andtarget == null, returning{-1, -1}safely.colPointer < matrix[rowPointer].lengthbefore reading elements to preventNullPointerExceptionandArrayIndexOutOfBoundsException.public final class RowColumnWiseSorted2dArrayBinarySearch.find()interface method.