Skip to content

Fix(searches): Correct column pointer initialization in RowColumnWiseSorted2dArrayBinarySearch #6333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

codingmydna
Copy link

  • 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.31%. Comparing base (a8ad162) to head (6ca8592).
Report is 10 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6333      +/-   ##
============================================
+ Coverage     74.17%   74.31%   +0.14%     
- Complexity     5362     5390      +28     
============================================
  Files           678      679       +1     
  Lines         18686    18820     +134     
  Branches       3625     3646      +21     
============================================
+ Hits          13860    13987     +127     
- Misses         4272     4275       +3     
- Partials        554      558       +4     

☔ 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
Copy link
Collaborator

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Incorrect column pointer initialization in RowColumnWiseSorted2dArrayBinarySearch
3 participants