Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start iterating over the matrix rows.
DSA Javascript
for (let [1] = 0; [1] < matrix.length; [1]++) { // code }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'col' or 'j' for row iteration causes confusion.
Using an undefined variable name.
✗ Incorrect
We use 'i' as the standard variable name for iterating over rows in a matrix.
2fill in blank
mediumComplete the code to check if the current element is zero.
DSA Javascript
if (matrix[i][[1]] === 0) { // code }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'i' for both row and column index.
Using variable names not declared in loops.
✗ Incorrect
We use 'j' to iterate over columns, so matrix[i][j] accesses the current element.
3fill in blank
hardFix the error in marking the first row zero flag.
DSA Javascript
if (matrix[0][j] === 0) { [1] = true; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'firstColZero' instead of 'firstRowZero'.
Using undefined variable names.
✗ Incorrect
The variable 'firstRowZero' is used to mark if the first row contains zero.
4fill in blank
hardFill both blanks to mark zeroes in first row and column.
DSA Javascript
if (matrix[i][j] === 0) { matrix[i][[1]] = 0; matrix[[2]][j] = 0; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'i' or 'j' instead of 0 for marking.
Using 1 which is not the first row or column.
✗ Incorrect
We mark the first column (index 0) of row i and the first row (index 0) of column j as zero.
5fill in blank
hardFill all three blanks to set matrix elements to zero based on markers.
DSA Javascript
for (let i = 1; i < matrix.length; i++) { for (let j = 1; j < matrix[0].length; j++) { if (matrix[i][[1]] === 0 || matrix[[2]][j] === 0) { matrix[i][j] = [3]; } } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for markers.
Setting matrix[i][j] to 1 instead of 0.
✗ Incorrect
We check the first column of row i and first row of column j for zero markers and set matrix[i][j] to 0.
