Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the first cell of the dp grid with the grid's first cell value.
DSA Javascript
dp[0][0] = grid[0][1][0];
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses () instead of square brackets []
Using dot notation which doesn't work for array indices
✗ Incorrect
We use square brackets [] to access elements in a 2D array in JavaScript.
2fill in blank
mediumComplete the code to fill the first row of the dp grid by accumulating sums from the left.
DSA Javascript
for (let j = 1; j < cols; j++) { dp[0][j] = dp[0][j - 1] [1] grid[0][j]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition
Using division which is not meaningful here
✗ Incorrect
We add the current grid value to the sum from the left cell to accumulate the path sum.
3fill in blank
hardFix the error in the code to correctly compute the minimum path sum for each cell.
DSA Javascript
dp[i][j] = Math.min(dp[i - 1][j], dp[i][j - 1]) [1] grid[i][j];
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition
Using division which is incorrect here
✗ Incorrect
We add the current grid value to the minimum of the top and left dp cells to get the minimum path sum.
4fill in blank
hardFill both blanks to complete the loops that fill the dp grid starting from row 1 and column 1.
DSA Javascript
for (let i = 1; i [1] rows; i++) { for (let j = 1; j [2] cols; j++) { dp[i][j] = Math.min(dp[i - 1][j], dp[i][j - 1]) + grid[i][j]; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= which causes index out of range errors
Using > or >= which won't run the loops correctly
✗ Incorrect
We use less than < to loop from 1 up to but not including rows and cols, matching array indices.
5fill in blank
hardFill both blanks to return the minimum path sum from the bottom-right cell of the dp grid.
DSA Javascript
return dp[1][2];
Attempts:
3 left
💡 Hint
Common Mistakes
Using dp[rows][cols] which is out of bounds
Mixing up rows and cols indices
✗ Incorrect
We access dp[rows - 1][cols - 1] to get the minimum path sum at the bottom-right corner.
