0
0
DSA Cprogramming~10 mins

Unique Paths in Grid DP in DSA C - 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 first row of the DP table with 1s.

DSA C
for (int j = 0; j < n; j++) {
    dp[0][j] = [1];
}
Drag options to blanks, or click blank then click option'
Aj
B0
C1
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Setting dp[0][j] to 0 instead of 1.
Using the loop variable j as the value.
2fill in blank
medium

Complete the code to initialize the first column of the DP table with 1s.

DSA C
for (int i = 0; i < m; i++) {
    dp[i][0] = [1];
}
Drag options to blanks, or click blank then click option'
Ai
Bm
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting dp[i][0] to 0 instead of 1.
Using the loop variable i as the value.
3fill in blank
hard

Fix the error in the code to correctly compute the number of unique paths for each cell.

DSA C
for (int i = 1; i < m; i++) {
    for (int j = 1; j < n; j++) {
        dp[i][j] = dp[i - 1][j] [1] dp[i][j - 1];
    }
}
Drag options to blanks, or click blank then click option'
A+
B*
C/
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Using division which is not meaningful here.
4fill in blank
hard

Fill both blanks to complete the nested loops iterating over the grid cells starting from (1,1).

DSA C
for (int [1] = 1; [2] < m; [1]++) {
    for (int j = 1; j < n; j++) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
    }
}
Drag options to blanks, or click blank then click option'
Ai
Bj
Ck
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables in declaration and condition.
Using 'j' for the outer loop which is for columns.
5fill in blank
hard

Fill all three blanks to return the total unique paths from top-left to bottom-right in the grid.

DSA C
int uniquePaths(int m, int n) {
    int dp[m][n];
    for (int i = 0; i < m; i++) dp[i][0] = 1;
    for (int j = 0; j < n; j++) dp[0][j] = 1;
    for (int i = 1; i < m; i++) {
        for (int j = 1; j < n; j++) {
            dp[i][j] = dp[i - 1][j] [1] dp[i][j - 1];
        }
    }
    return dp[[2]][[3]];
}
Drag options to blanks, or click blank then click option'
A+
B-
Cm - 1
Dn - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' for summing paths.
Returning dp[m][n] which is out of bounds.