Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the minimum cuts array with the maximum possible cuts.
DSA Go
minCuts := make([]int, n) for i := 0; i < n; i++ { minCuts[i] = [1] }
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing minCuts[i] with i or i-1 which is incorrect for the initial maximum cuts.
Using n instead of n-1 which is out of index range.
✗ Incorrect
We initialize minCuts[i] with the maximum cuts possible, which is n-1 (cut after every character).
2fill in blank
mediumComplete the code to check if the substring s[j:i+1] is a palindrome using DP table.
DSA Go
if s[j] == s[i] && (i-j < 2 || dp[j+1][i-1] == [1]) { dp[j][i] = true }
Attempts:
3 left
💡 Hint
Common Mistakes
Using false instead of true in the condition.
Checking dp[j][i] instead of dp[j+1][i-1].
✗ Incorrect
A substring is palindrome if the characters at ends match and the inner substring is palindrome (dp[j+1][i-1] == true).
3fill in blank
hardFix the error in updating minimum cuts when substring s[j:i+1] is palindrome.
DSA Go
if j == 0 { minCuts[i] = 0 } else { minCuts[i] = min(minCuts[i], [1]) }
Attempts:
3 left
💡 Hint
Common Mistakes
Using minCuts[j] instead of minCuts[j-1].
Subtracting 1 instead of adding 1.
✗ Incorrect
We update minCuts[i] with minCuts[j-1] + 1 because we cut before index j.
4fill in blank
hardFill both blanks to complete the nested loops for DP palindrome partitioning.
DSA Go
for i := 0; i < n; i++ { for j := 0; j <= [1]; j++ { if s[j] == s[i] && (i-j < 2 || dp[j+1][i-1] == true) { dp[j][i] = true if j == 0 { minCuts[i] = 0 } else { minCuts[i] = min(minCuts[i], minCuts[[2]] + 1) } } } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using j instead of i in inner loop condition.
Using j or i instead of j-1 for minCuts index.
✗ Incorrect
Inner loop runs j from 0 to i. Update minCuts[i] using minCuts[j-1] + 1 for cut before j.
5fill in blank
hardFill all three blanks to complete the min function and return statement.
DSA Go
func min(a, b int) int { if a [1] b { return a } return [2] } return minCuts[[3]]
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < in min function.
Returning a instead of b in else case.
Returning minCuts[i] instead of minCuts[n-1].
✗ Incorrect
min returns smaller of a and b. Return minCuts[n-1] as minimum cuts for full string.
