0
0
DSA Typescriptprogramming~10 mins

Tabulation Bottom Up 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[] = new Array(n + 1).fill([1]);
Drag options to blanks, or click blank then click option'
A1
B-1
C0
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 causes incorrect base values.
Using null or -1 can cause runtime errors in calculations.
2fill in blank
medium

Complete the code to set the base case for the DP array.

DSA Typescript
dp[0] = [1];
Drag options to blanks, or click blank then click option'
An
B1
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting dp[0] to 0 means no ways to make sum zero, which is incorrect.
Setting dp[0] to n or -1 is logically wrong for base case.
3fill in blank
hard

Fix the error in the loop condition to correctly iterate over sums.

DSA Typescript
for (let sum = 1; sum [1]= target; sum++) {
Drag options to blanks, or click blank then click option'
A<
B>=
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using < excludes the target sum from calculation.
Using > or >= causes the loop to never run or run incorrectly.
4fill in blank
hard

Fill both blanks to update the DP array correctly inside the nested loop.

DSA Typescript
if (sum >= nums[i]) {
  dp[sum] = dp[sum] + dp[sum [1] nums[i]];
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of - causes wrong indexing and errors.
Using * or / is not meaningful in this context.
5fill in blank
hard

Fill all three blanks to complete the tabulation function for subset sum count.

DSA Typescript
function countSubsets(nums: number[], target: number): number {
  const dp: number[] = new Array(target + 1).fill([1]);
  dp[0] = [2];
  for (let i = 0; i < nums.length; i++) {
    for (let sum = target; sum >= [3]; sum--) {
      if (sum >= nums[i]) {
        dp[sum] += dp[sum - nums[i]];
      }
    }
  }
  return dp[target];
}
Drag options to blanks, or click blank then click option'
A0
B1
Cnums[i]
Dtarget
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing dp with 1 instead of 0 causes wrong counts.
Setting dp[0] to 0 means no base case.
Iterating sums forward causes overcounting.