0
0
DSA Typescriptprogramming~10 mins

Unique Paths in Grid DP in DSA Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aundefined
B1
Cnull
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 initializes paths incorrectly.
Using null or undefined causes runtime errors.
2fill in blank
medium

Complete 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'
A1
B0
C-1
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Setting starting point to 0 means no paths start there.
Using negative or null values causes errors.
3fill in blank
hard

Fix 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'
Am
Bn
Cdp.length
Ddp[0].length
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.
4fill in blank
hard

Fill 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'
Am
Bn
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 as indices returns wrong cell.
Swapping m and n causes wrong indexing.
5fill in blank
hard

Fill 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'
Am
Bn
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up m and n in parameters and array dimensions.
Using inconsistent variable names causes errors.