Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the DP array with zeros.
DSA Typescript
const dp: number[][] = Array(m).fill(0).map(() => Array(n).fill([1]));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 initializes paths incorrectly.
Using null or undefined causes runtime errors.
✗ Incorrect
We fill the DP array with zeros to start counting paths from zero.
2fill in blank
mediumComplete the code to set the starting point paths count to 1.
DSA Typescript
dp[0][0] = [1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting starting point to 0 means no paths start there.
Using negative or null values causes errors.
✗ Incorrect
The starting cell has exactly one path to itself.
3fill in blank
hardFix the error in the nested loops to correctly iterate over the grid.
DSA Typescript
for (let i = 0; i < [1]; i++) { for (let j = 0; j < n; j++) { if (i === 0 && j === 0) continue; dp[i][j] = (i > 0 ? dp[i - 1][j] : 0) + (j > 0 ? dp[i][j - 1] : 0); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using n in outer loop causes index errors.
Using dp.length or dp[0].length may confuse rows and columns.
✗ Incorrect
The outer loop should run from 0 to m (rows).
4fill in blank
hardFill both blanks to correctly return the total unique paths from top-left to bottom-right.
DSA Typescript
return dp[[1] - 1][[2] - 1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 as indices returns wrong cell.
Swapping m and n causes wrong indexing.
✗ Incorrect
The bottom-right cell is at index m-1, n-1 in the DP array.
5fill in blank
hardFill all three blanks to complete the function that calculates unique paths in an m x n grid.
DSA Typescript
function uniquePaths([1]: number, [2]: number): number { const dp: number[][] = Array([1]).fill(0).map(() => Array([2]).fill(0)); dp[0][0] = 1; for (let i = 0; i < [1]; i++) { for (let j = 0; j < [2]; j++) { if (i === 0 && j === 0) continue; dp[i][j] = (i > 0 ? dp[i - 1][j] : 0) + (j > 0 ? dp[i][j - 1] : 0); } } return dp[[1] - 1][[2] - 1]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up m and n in parameters and array dimensions.
Using inconsistent variable names causes errors.
✗ Incorrect
The function parameters and DP array dimensions use m and n consistently.