Workspace Row With Maximum Ones
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Row with Maximum Ones visualizer

Learn Row with Maximum Ones with a step-by-step Binary Search visualizer, JavaScript source code and a worked example. Practice matrices.

INTERACTIVE EXECUTION STUDIO
LEARN BY DOING

Predict. Execute. Understand.

Follow the source code, inspect live state changes, and predict the next operation before revealing it.

1 / 4Execution step
Reference example · JavaScript
Inspect reference input
[
  [
    0,
    0,
    1
  ],
  [
    0,
    1,
    1
  ],
  [
    1,
    1,
    1
  ]
]

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
let j=a[0].length-1,b=-1;
for(let i=0;
i<a.length;
i++)while(j>=0&&a[i][j]===1){
b=i;
s("Move left across ones",{
Matrix:a,BestRow:[b],Position:[i,j]
});
j--
}
return b
};

Execution canvas

Active Changed
STEP 1

Move left across ones

Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.

Matrix3 rows
BestRow1 items
Position2 items
Keyboard: Space to play · Left / Right to stepExplore next problem

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

[
  [
    0,
    0,
    1
  ],
  [
    0,
    1,
    1
  ],
  [
    1,
    1,
    1
  ]
]

Execution steps

  1. Move left across ones

Computed output

2
JavaScript reference implementation
const solve = (a,s)=>{
  let j=a[0].length-1,b=-1;
  for(let i=0;
  i<a.length;
  i++)while(j>=0&&a[i][j]===1){
    b=i;
    s("Move left across ones",{
      Matrix:a,BestRow:[b],Position:[i,j]
    });
    j--
  }
  return b
};

Continue learning

Practice related DSA questions in the same topic.