neetcode-gh / leetcode

Leetcode solutions
MIT License
5.63k stars 2.32k forks source link

Incorrect Binary Search in 0074-search-a-2d-matrix.go #3045

Closed jyotirmoydotdev closed 1 year ago

jyotirmoydotdev commented 1 year ago

Description: The code in the file go/0074-search-a-2d-matrix.go is incorrect and fails to pass a significant number of test cases on LeetCode. This issue aims to address the problems in the code and provide a corrected version.


Problem Description: The current code utilizes a binary search approach to find the target value in a 2D matrix. However, there is a logical issue in the code that causes it to fail for specific input scenarios.


Proposed Changes: The proposed changes to the code include modifying the condition in line 21 if top >= bot to if !(top <= bot) for correct logic. This change will ensure that the code behaves correctly in all cases.


Steps to Reproduce: To reproduce the issue, you can run the current code on LeetCode, where it fails to pass 107 out of 133 test cases.


Expected Behavior: After the proposed changes, the corrected code is expected to pass all the test cases on LeetCode and provide the correct result for the given problem.

rahulmangla28 commented 1 year ago

Please assign this issue to me.

jyotirmoydotdev commented 1 year ago

I've submitted a pull request, so there's no need to assign anyone. I'm simply awaiting the merge.

@neetcode-gh, could you please merge the pull request at your earliest convenience?

PR URL: https://github.com/neetcode-gh/leetcode/pull/3046