Skip to content

Conversation

@codingmydna
Copy link
Contributor

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Closes #6332

This pull request fixes a bug in the RowColumnWiseSorted2dArrayBinarySearch.java file where the column pointer was incorrectly initialized.

The Problem:
The column pointer (colPointer) was being initialized with matrix.length - 1. However, matrix.length returns the number of rows, not columns. This causes the algorithm to start at an incorrect position and fail for any matrix that is not square.

The Solution:
I have corrected the initialization to int colPointer = matrix[0].length - 1;. This correctly uses the length of the first row to determine the number of columns, ensuring the pointer is set to the last column's index as intended by the algorithm's logic.

@codecov-commenter
Copy link

codecov-commenter commented Jul 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.33%. Comparing base (ebf5c3d) to head (0d4411a).

Additional details and impacted files
@@ Coverage Diff @@ ## master #6333 +/- ## ========================================= Coverage 74.33% 74.33% Complexity 5391 5391 ========================================= Files 679 679 Lines 18820 18820 Branches 3646 3646 ========================================= Hits 13989 13989 Misses 4274 4274 Partials 557 557 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@codingmydna codingmydna force-pushed the fix/2d-array-search-bug branch from 41292a7 to 6ca8592 Compare July 1, 2025 13:17
DenizAltunkapan
DenizAltunkapan previously approved these changes Jul 1, 2025
Copy link
Member

@DenizAltunkapan DenizAltunkapan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why created as Draft? Looks good to me.

@codingmydna
Copy link
Contributor Author

Why created as Draft? Looks good to me.

I thought it didn't pass a CI check, Infer.
If it doesn't matter, then I'll switch to Ready for review

@codingmydna codingmydna marked this pull request as ready for review July 2, 2025 00:34
@codingmydna codingmydna force-pushed the fix/2d-array-search-bug branch from 3dd5491 to bae6cc9 Compare July 2, 2025 10:36
Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak siriak enabled auto-merge (squash) July 2, 2025 12:49
@siriak siriak merged commit 712ada5 into TheAlgorithms:master Jul 2, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants