What is the error in my code?


#1

Comm public int searchMatrix(ArrayList<ArrayList> A, int B)
{
int m=A.size();
int n=A.get(0).size()-1;
int i=0;
int j=n;
while(j>=0 && i<m)
{
if(A.get(i).get(j)==B)
{
return 1;
}
else if(A.get(i).get(j)>B)
{
i++;
}
else if(A.get(i).get(j)<B)
{
j–;
}
}
return 0;

}

}
ent body goes here.

A :
[
[3, 3, 11, 12, 14]
[16, 17, 30, 34, 35]
[45, 48, 49, 50, 52]
[56, 59, 63, 63, 65]
[67, 71, 72, 73, 79]
[80, 84, 85, 85, 88]
[88, 91, 92, 93, 94]
]
B : 94

It is not working for this test case


#2

if current element is greater than B we have to move left so j–
for A.get(i).get(j)>B do j–
and for A.get(i).get(j)<B do i++