Challenge - 5 Problems
Palindrome Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Palindrome Check Function
What is the output of the following Go code that checks if a string is a palindrome?
DSA Go
package main import ( "fmt" ) func isPalindrome(s string) bool { for i := 0; i < len(s)/2; i++ { if s[i] != s[len(s)-1-i] { return false } } return true } func main() { fmt.Println(isPalindrome("radar")) fmt.Println(isPalindrome("hello")) }
Attempts:
2 left
💡 Hint
Check character pairs from start and end moving towards the center.
✗ Incorrect
The function compares characters from the start and end. 'radar' reads the same forwards and backwards, so true. 'hello' does not, so false.
🧠 Conceptual
intermediateUnderstanding Palindrome Detection Logic
Which statement best describes the logic used to detect a palindrome in a string?
Attempts:
2 left
💡 Hint
Think about how to verify if a string reads the same forwards and backwards.
✗ Incorrect
The palindrome check compares characters from both ends towards the center. If any pair is different, it is not a palindrome.
❓ Predict Output
advancedOutput of Palindrome Check with Unicode Characters
What is the output of this Go code that checks if a string with Unicode characters is a palindrome?
DSA Go
package main import ( "fmt" ) func isPalindrome(s string) bool { runes := []rune(s) for i := 0; i < len(runes)/2; i++ { if runes[i] != runes[len(runes)-1-i] { return false } } return true } func main() { fmt.Println(isPalindrome("あいいあ")) fmt.Println(isPalindrome("あいえあ")) }
Attempts:
2 left
💡 Hint
Use rune slices to handle Unicode characters correctly.
✗ Incorrect
The code converts the string to runes to handle Unicode properly. 'あいいあ' is a palindrome, 'あいえあ' is not.
🔧 Debug
advancedIdentify the Error in Palindrome Function
What error will this Go code produce when checking if a string is a palindrome?
DSA Go
package main import ( "fmt" ) func isPalindrome(s string) bool { for i := 0; i <= len(s)/2; i++ { if s[i] != s[len(s)-1-i] { return false } } return true } func main() { fmt.Println(isPalindrome("level")) }
Attempts:
2 left
💡 Hint
Simulate the loop indices for 'level' (length 5).
✗ Incorrect
The code compiles and prints true. The loop condition i <= len(s)/2 works because indices stay within bounds; for odd lengths, the middle character compares to itself.
🚀 Application
expertCount Palindromic Substrings in a String
Given the string "abba", how many palindromic substrings does it contain?
Attempts:
2 left
💡 Hint
Consider all substrings and count those that read the same forwards and backwards.
✗ Incorrect
Palindromic substrings: 'a'(0-0), 'b'(1-1), 'b'(2-2), 'a'(3-3), 'bb'(1-2), 'abba'(0-3). Total 6.
