Repository navigation
fix(searches): fix out-of-bounds in single-row and single-column in BinarySearch2dArray - #7724
Conversation
…inarySearch2dArray
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
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 #7724 +/- ##
============================================
+ Coverage 82.27% 82.29% +0.01%
- Complexity 8410 8412 +2
============================================
Files 843 843
Lines 26144 26146 +2
Branches 5102 5103 +1
============================================
+ Hits 21510 21516 +6
+ Misses 3842 3841 -1
+ Partials 792 789 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks @DenizAltunkapan |
clang-format -i --style=file path/to/your/file.javaDescription
This pull request fixes out-of-bounds errors on single-row and single-column matrices, and exposes
binarySearchas a public method inBinarySearch2dArray:binarySearch(int[][] arr, int target), whenrowCount == 1, the helperbinarySearch(arr, target, 0, 0, colCount)was called withcolCountinstead ofcolCount - 1. Because the helper uses an inclusive upper bound (colStart <= colEnd), searching for an element greater thanarr[0][colCount - 1]causedmidIndexto equalcolCount, triggering anArrayIndexOutOfBoundsException. Updated to passcolCount - 1.colCount == 1,midColis 0. AccessingmidCol - 1threwArrayIndexOutOfBoundsException: Index -1 out of bounds for length 1. Added an edge-case guard returning{-1, -1}whencolCount == 1after checkingmidCol.binarySearch(int[][] arr, int target)from package-private topublic static.