Skip to content

Bug Report for search-2d-matrix #5588

@rohit-ira

Description

@rohit-ira

Bug Report for https://neetcode.io/problems/search-2d-matrix

class Solution {
public:
bool searchMatrix(vector<vector>& arr, int t) {
int i=0, j=arr.size()-1;
while(i<=j) {
int m = (i+j)>>1;
if(arr[m][0]>t) j=m-1;
else if(arr[m][0]==t) return true;
else i=m+1;
}
cout<<i<<" "<<j<<endl;
if(i>arr.size()-1) return false;
int row = j;
i=0; j=arr[row].size()-1;
while(i<=j) {
int m = (i+j)>>1;
if(arr[row][m]>t) j=m-1;
else if(arr[row][m]==t) return true;
else i=m+1;
}
return false;
}
};

When I run this code multiple times, its getting accepted at random.

Focus on the last test case.

This is the proof. After running the same code 3-4 times, its getting accepted.
Image

Same code when I ran it the first time.
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions