Back to questionsDSA Visualizers: 388 Coding Questions Search a 2D Matrix II visualizer Learn Search a 2D Matrix II with a step-by-step Binary Search visualizer, JavaScript source code and a worked example. Practice matrices.
INTERACTIVE EXECUTION STUDIOLEARN BY DOING Predict. Execute. Understand. Follow the source code, inspect live state changes, and predict the next operation before revealing it.
1 / 5 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input {
"a": [
[
1,
4,
7
],
[
2,
5,
8
],
[
3,
6,
9
]
],
"k": 6
} Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = ({
2 a,k
3 },s)=>{
4 let i=0 ,j=a[0 ].length-1 ;
5 while (i<a.length&&j>=0 ){
6 s("Eliminate row or column",{
7 Matrix:a,Cell:[i,j]
8 });
9 if (a[i][j]===k)return true ;
10 if (a[i][j]>k)j--;
11 else i++
12 }
13 return false
14 };
Execution canvas Active ChangedSTEP 1 Eliminate row or column Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.
Worked example and algorithm walkthrough Topic: Binary Search · Matrices
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 {
"a": [
[
1,
4,
7
],
[
2,
5,
8
],
[
3,
6,
9
]
],
"k": 6
} Execution steps Eliminate row or column Computed output true JavaScript reference implementation const solve = ({
a,k
},s)=>{
let i=0,j=a[0].length-1;
while(i<a.length&&j>=0){
s("Eliminate row or column",{
Matrix:a,Cell:[i,j]
});
if(a[i][j]===k)return true;
if(a[i][j]>k)j--;
else i++
}
return false
};Continue learning Practice related DSA questions in the same topic.