0
0
DSA Cprogramming~10 mins

Partition Equal Subset Sum 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 calculate the total sum of the array elements.

DSA C
int totalSum = 0;
for (int i = 0; i < n; i++) {
    totalSum [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 subtraction instead of addition.
Using '*=' or '/=' will not accumulate the sum correctly.
2fill in blank
medium

Complete the code to check if the total sum is odd, which means partition is impossible.

DSA C
if (totalSum [1] 2 != 0) {
    return false;
}
Drag options to blanks, or click blank then click option'
A%
B/
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' instead of '%' will not check odd/even correctly.
Using '==' or '!=' without modulus will cause logic errors.
3fill in blank
hard

Fix the error in the recursive function call to check subset sum.

DSA C
bool canPartition(int* nums, int n, int sum) {
    if (sum == 0) return true;
    if (n == 0 || sum < 0) return false;
    return canPartition(nums, n - 1, sum) || canPartition(nums, n - 1, [1] - nums[n - 1]);
}
Drag options to blanks, or click blank then click option'
Asum - nums[n - 1]
Bsum + nums[n - 1]
Cn
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Adding nums[n-1] instead of subtracting causes wrong sum calculation.
Passing 'n' instead of 'sum' causes type mismatch.
4fill in blank
hard

Fill both blanks to create a dynamic programming table initialization for subset sum.

DSA C
bool dp[n + 1][sum + 1];
for (int i = 0; i <= n; i++) {
    dp[i][0] = [1];
}
for (int j = 1; j <= sum; j++) {
    dp[0][j] = [2];
}
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting dp[i][0] to false breaks the base case.
Setting dp[0][j] to true allows impossible sums.
5fill in blank
hard

Fill the blank to complete the DP state update for subset sum problem.

DSA C
for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= sum; j++) {
        if (nums[i - 1] <= j) {
            dp[i][j] = dp[i - 1][j] || dp[i - 1][[1]];
        } else {
            dp[i][j] = dp[i - 1][j];
        }
    }
}
Drag options to blanks, or click blank then click option'
Ai
Bj + nums[i - 1]
Cj - nums[i - 1]
Di - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Adding nums[i-1] instead of subtracting causes wrong indexing.
Using wrong indices for dp causes logic errors.