Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.
Example input
[
[
1,
3,
5
],
[
2,
6,
9
],
[
3,
6,
9
]
]
Execution steps
Count values at most 5
Count values at most 3
Count values at most 4
Computed output
5
JavaScript reference implementation
const solve = (a,s)=>{
let l=Math.min(...a.map(r=>r[0])),r=Math.max(...a.map(r=>r.at(-1))),k=Math.floor(a.length*a[0].length/2);
while(l<r){
let m=(l+r)>>1,c=0;
for(let row of a){
let x=0,y=row.length;
while(x<y){
let j=(x+y)>>1;
if(row[j]<=m)x=j+1;
else y=j
}
c+=x
}
s("Count values at most "+m,{
Matrix:a,Bounds:[l,m,r],Count:[c]
});
if(c<=k)l=m+1;
else r=m
}
return l
};