0
0
DSA Cprogramming~10 mins

Coin Change Total Number of Ways 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 ways array with 0.

DSA C
int ways[amount + 1] = {0};
ways[0] = [1];
Drag options to blanks, or click blank then click option'
A1
B0
Camount
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting ways[0] to 0 will cause the algorithm to fail to count any combinations.
Using negative or amount value instead of 1.
2fill in blank
medium

Complete the code to update the ways array inside the nested loop.

DSA C
for (int i = 0; i < n; i++) {
    for (int j = coins[i]; j <= amount; j++) {
        ways[j] += [1];
    }
}
Drag options to blanks, or click blank then click option'
Aways[j - coins[i]]
Bcoins[i]
Cj
Dways[j]
Attempts:
3 left
💡 Hint
Common Mistakes
Adding coins[i] directly instead of ways[j - coins[i]].
Using ways[j] on the right side causes incorrect counting.
3fill in blank
hard

Fix the error in the loop condition to avoid out-of-bounds access.

DSA C
for (int j = coins[i]; j [1] amount; j++) {
    ways[j] += ways[j - coins[i]];
}
Drag options to blanks, or click blank then click option'
A>
B<
C<=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using < causes the last amount to be skipped.
Using > or >= causes the loop to not run or run incorrectly.
4fill in blank
hard

Fill both blanks to complete the function signature and return statement.

DSA C
int [1](int coins[], int n, int amount) {
    int ways[amount + 1] = {0};
    ways[0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = coins[i]; j <= amount; j++) {
            ways[j] += ways[j - coins[i]];
        }
    }
    return [2];
}
Drag options to blanks, or click blank then click option'
AcountWays
Bways[amount]
Camount
Dcoins
Attempts:
3 left
💡 Hint
Common Mistakes
Returning amount or coins instead of ways[amount].
Using a wrong function name that does not match the problem.
5fill in blank
hard

Fill all three blanks to complete the main function that calls countWays and prints the result.

DSA C
#include <stdio.h>

int countWays(int coins[], int n, int amount);

int main() {
    int coins[] = {1, 2, 5};
    int n = sizeof(coins) / sizeof(coins[0]);
    int amount = 5;
    int result = [1](coins, n, amount);
    printf("Total ways to make %d: %d\n", [2], [3]);
    return 0;
}
Drag options to blanks, or click blank then click option'
AcountWays
Bamount
Cresult
Dcoins
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names in printf.
Calling a wrong function or passing wrong arguments.