Challenge - 5 Problems
Tabulation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Fibonacci Tabulation
What is the output of this code that uses bottom-up DP to find the 6th Fibonacci number?
DSA Python
def fib_tab(n): dp = [0] * (n+1) dp[1] = 1 for i in range(2, n+1): dp[i] = dp[i-1] + dp[i-2] return dp[n] print(fib_tab(6))
Attempts:
2 left
💡 Hint
Remember Fibonacci sequence starts 0,1,1,2,3,5,8...
✗ Incorrect
The 6th Fibonacci number (0-based index) is 8 using bottom-up DP.
❓ Predict Output
intermediateNumber of ways to climb stairs
What is the output of this code that counts ways to climb 4 stairs taking 1 or 2 steps at a time?
DSA Python
def climb_stairs(n): dp = [0] * (n+1) dp[0] = 1 for i in range(1, n+1): dp[i] = dp[i-1] if i > 1: dp[i] += dp[i-2] return dp[n] print(climb_stairs(4))
Attempts:
2 left
💡 Hint
Think of ways to reach step i from i-1 and i-2.
✗ Incorrect
The ways to climb 4 stairs are 5 using bottom-up DP.
❓ Predict Output
advancedLongest Common Subsequence length
What is the output of this code that finds the length of the longest common subsequence of 'abcde' and 'ace' using bottom-up DP?
DSA Python
def lcs_length(s1, s2): m, n = len(s1), len(s2) dp = [[0]*(n+1) for _ in range(m+1)] for i in range(1, m+1): for j in range(1, n+1): if s1[i-1] == s2[j-1]: dp[i][j] = dp[i-1][j-1] + 1 else: dp[i][j] = max(dp[i-1][j], dp[i][j-1]) return dp[m][n] print(lcs_length('abcde', 'ace'))
Attempts:
2 left
💡 Hint
Longest common subsequence of 'abcde' and 'ace' is 'ace'.
✗ Incorrect
The LCS length is 3 for 'ace'.
🔧 Debug
advancedIdentify error in coin change tabulation
What error does this code produce when trying to find number of ways to make amount 5 with coins [1,2,3] using bottom-up DP?
DSA Python
def coin_change(coins, amount): dp = [0] * (amount+1) dp[0] = 1 for coin in coins: for x in range(coin, amount+1): dp[x] += dp[x-coin] return dp[amount] print(coin_change([1,2,3], 5))
Attempts:
2 left
💡 Hint
Count ways to make 5 with coins 1,2,3 carefully.
✗ Incorrect
There is no error; the code correctly computes 5 ways using bottom-up DP.
🧠 Conceptual
expertMinimum edit distance tabulation result
Given strings 'kitten' and 'sitting', what is the minimum edit distance computed by this bottom-up DP code?
DSA Python
def min_edit_distance(s1, s2): m, n = len(s1), len(s2) dp = [[0]*(n+1) for _ in range(m+1)] for i in range(m+1): dp[i][0] = i for j in range(n+1): dp[0][j] = j for i in range(1, m+1): for j in range(1, n+1): if s1[i-1] == s2[j-1]: dp[i][j] = dp[i-1][j-1] else: dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) return dp[m][n] print(min_edit_distance('kitten', 'sitting'))
Attempts:
2 left
💡 Hint
Edit distance counts insertions, deletions, substitutions.
✗ Incorrect
Minimum edit distance between 'kitten' and 'sitting' is 3.
