Challenge - 5 Problems
Tabulation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Bottom-Up DP Fibonacci Calculation
What is the output of this C# code that calculates Fibonacci numbers using bottom-up tabulation?
DSA C#
int n = 6; int[] dp = new int[n + 1]; dp[0] = 0; dp[1] = 1; for (int i = 2; i <= n; i++) { dp[i] = dp[i - 1] + dp[i - 2]; } Console.WriteLine(string.Join(", ", dp));
Attempts:
2 left
💡 Hint
Remember Fibonacci starts with 0 and 1, and each next number is sum of previous two.
✗ Incorrect
The code initializes dp[0] = 0 and dp[1] = 1. Then each dp[i] is dp[i-1] + dp[i-2]. So dp array becomes [0,1,1,2,3,5,8].
❓ Predict Output
intermediateOutput of Bottom-Up DP for Coin Change Ways
What is the output of this C# code that calculates the number of ways to make amount 5 using coins {1, 2} with bottom-up DP?
DSA C#
int amount = 5; int[] coins = {1, 2}; int[] dp = new int[amount + 1]; dp[0] = 1; foreach (int coin in coins) { for (int i = coin; i <= amount; i++) { dp[i] += dp[i - coin]; } } Console.WriteLine(dp[amount]);
Attempts:
2 left
💡 Hint
Think about combinations of 1s and 2s that sum to 5.
✗ Incorrect
The ways to make 5 are: five 1s, three 1s + one 2, one 1 + two 2s. Total 3 ways.
🧠 Conceptual
advancedUnderstanding DP Table Construction Order
In bottom-up DP, why do we fill the table starting from the smallest subproblems to the largest?
Attempts:
2 left
💡 Hint
Think about dependencies between subproblems.
✗ Incorrect
Bottom-up DP solves smaller subproblems first because their results are needed to solve bigger subproblems. This order ensures all needed values are ready.
🔧 Debug
advancedIdentify the Bug in Bottom-Up DP for Climbing Stairs
What error does this C# code produce when calculating ways to climb 4 stairs taking 1 or 2 steps at a time?
DSA C#
int n = 4; int[] dp = new int[n + 1]; dp[0] = 1; dp[1] = 1; for (int i = 2; i <= n; i++) { dp[i] = dp[i - 1] + dp[i - 3]; } Console.WriteLine(dp[n]);
Attempts:
2 left
💡 Hint
Check the index used inside the loop for dp array access.
✗ Incorrect
At i=2, dp[i-3] is dp[-1], which is invalid index causing IndexOutOfRangeException.
🚀 Application
expertFinal DP Table for Longest Increasing Subsequence Length
Given the array [10, 9, 2, 5, 3, 7, 101, 18], what is the final dp table (lengths of LIS ending at each index) after bottom-up DP computation?
DSA C#
int[] nums = {10, 9, 2, 5, 3, 7, 101, 18}; int n = nums.Length; int[] dp = new int[n]; for (int i = 0; i < n; i++) dp[i] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] > nums[j]) { dp[i] = Math.Max(dp[i], dp[j] + 1); } } } Console.WriteLine(string.Join(", ", dp));
Attempts:
2 left
💡 Hint
Each dp[i] stores length of longest increasing subsequence ending at i.
✗ Incorrect
The dp array after computation is [1,1,1,2,2,3,4,4]. For example, at index 5 (value 7), LIS length is 3 (2,3,7).
