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 with mixed case and spaces
What is the output of this Rust code that checks if a string is a palindrome ignoring case and spaces?
DSA Rust
fn is_palindrome(s: &str) -> bool { let filtered: String = s.chars() .filter(|c| c.is_alphanumeric()) .map(|c| c.to_ascii_lowercase()) .collect(); filtered == filtered.chars().rev().collect::<String>() } fn main() { let test_str = "A man a plan a canal Panama"; println!("{}", is_palindrome(test_str)); }
Attempts:
2 left
💡 Hint
Think about how the function ignores spaces and case before checking.
✗ Incorrect
The function removes non-alphanumeric characters and converts all letters to lowercase, so the phrase "A man a plan a canal Panama" is recognized as a palindrome.
❓ Predict Output
intermediateResult of palindrome check on numeric string
What does this Rust code print when checking if the string "12321" is a palindrome?
DSA Rust
fn is_palindrome(s: &str) -> bool { s.chars().eq(s.chars().rev()) } fn main() { let num_str = "12321"; println!("{}", is_palindrome(num_str)); }
Attempts:
2 left
💡 Hint
Check if the string reads the same forwards and backwards.
✗ Incorrect
The string "12321" is the same forwards and backwards, so the function returns true.
❓ Predict Output
advancedOutput of palindrome check with Unicode characters
What is the output of this Rust code checking if the string "あいいあ" is a palindrome?
DSA Rust
fn is_palindrome(s: &str) -> bool { s.chars().eq(s.chars().rev()) } fn main() { let unicode_str = "あいいあ"; println!("{}", is_palindrome(unicode_str)); }
Attempts:
2 left
💡 Hint
Unicode characters can be compared like normal characters in Rust.
✗ Incorrect
The string "あいいあ" reads the same forwards and backwards, so the function returns true.
❓ Predict Output
advancedOutput of palindrome check ignoring punctuation
What does this Rust code print when checking if "Madam, I'm Adam." is a palindrome ignoring punctuation and case?
DSA Rust
fn is_palindrome(s: &str) -> bool { let filtered: String = s.chars() .filter(|c| c.is_alphanumeric()) .map(|c| c.to_ascii_lowercase()) .collect(); filtered == filtered.chars().rev().collect::<String>() } fn main() { let phrase = "Madam, I'm Adam."; println!("{}", is_palindrome(phrase)); }
Attempts:
2 left
💡 Hint
Punctuation is removed before checking palindrome.
✗ Incorrect
After removing punctuation and lowering case, the phrase reads the same forwards and backwards.
🧠 Conceptual
expertWhy is using chars().eq(chars().rev()) better than reversing string bytes for palindrome check?
Which reason best explains why checking palindrome with s.chars().eq(s.chars().rev()) is better than reversing the string bytes directly in Rust?
Attempts:
2 left
💡 Hint
Think about how Unicode characters are stored in memory.
✗ Incorrect
Unicode characters can be multiple bytes, so reversing bytes can break characters. Using chars() ensures each character is handled properly.
