Challenge - 5 Problems
Palindrome Partitioning Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Palindrome Partitioning for 'aab'
What is the output of the following code that finds all palindrome partitions of the string 'aab'?
DSA Python
def is_palindrome(s): return s == s[::-1] def backtrack(s, start, path, result): if start == len(s): result.append(path[:]) return for end in range(start + 1, len(s) + 1): if is_palindrome(s[start:end]): path.append(s[start:end]) backtrack(s, end, path, result) path.pop() result = [] backtrack('aab', 0, [], result) print(result)
Attempts:
2 left
💡 Hint
Check all substrings and only add those which are palindromes.
✗ Incorrect
The code finds all partitions where each substring is a palindrome. For 'aab', the partitions are ['a', 'a', 'b'] and ['aa', 'b'].
🧠 Conceptual
intermediateNumber of Palindrome Partitions for 'racecar'
How many palindrome partitions does the string 'racecar' have?
Attempts:
2 left
💡 Hint
Consider all ways to split 'racecar' into palindromic substrings.
✗ Incorrect
The string 'racecar' has 4 palindrome partitions: ['r','a','c','e','c','a','r'], ['r','a','cec','a','r'], ['r','aceca','r'], ['racecar'].
🔧 Debug
advancedIdentify the Error in Palindrome Partitioning Code
What error does the following code produce when run?
DSA Python
def is_palindrome(s): return s == s[::-1] def backtrack(s, start, path, result): if start == len(s): result.append(path) return for end in range(start + 1, len(s) + 1): if is_palindrome(s[start:end]): path.append(s[start:end]) backtrack(s, end, path, result) path.pop() result = [] backtrack('aba', 0, [], result) print(result)
Attempts:
2 left
💡 Hint
Check how the path list is appended to result.
✗ Incorrect
Appending 'path' directly adds a reference, so all entries in result point to the same list, causing duplicates or unexpected results.
🚀 Application
advancedFind All Palindrome Partitions of 'level'
Which option correctly lists all palindrome partitions of the string 'level'?
Attempts:
2 left
💡 Hint
Check which substrings are palindromes.
✗ Incorrect
Only 'l', 'e', 'v', 'eve', and 'level' are palindromes in the string 'level'.
📝 Syntax
expertIdentify Syntax Error in Palindrome Partitioning Code
Which option contains a syntax error in the palindrome partitioning backtracking code?
Attempts:
2 left
💡 Hint
Check for missing colons in for loops.
✗ Incorrect
Option C is missing a colon ':' at the end of the for loop line, causing a syntax error.
