Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the left pointer at the start of the string.
DSA Rust
let mut left = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Starting left pointer at 1 skips the first character.
Starting at s.len() is out of bounds.
✗ Incorrect
The left pointer should start at index 0 to begin checking from the start of the string.
2fill in blank
mediumComplete the code to initialize the right pointer at the end of the string.
DSA Rust
let mut right = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using s.len() causes out of bounds error.
Starting at 0 means left and right pointers start at same place.
✗ Incorrect
The right pointer should start at the last valid index, which is length minus one.
3fill in blank
hardFix the error in the while loop condition to continue while left is less than right.
DSA Rust
while [1] < right {
Attempts:
3 left
💡 Hint
Common Mistakes
Using right < right is always false.
Using left + 1 < right skips first comparison.
✗ Incorrect
The loop should run while left pointer is less than right pointer to compare characters.
4fill in blank
hardFill both blanks to skip non-alphanumeric characters from left and right pointers.
DSA Rust
while left < right && !s.chars().nth(left).unwrap().is_alphanumeric() [1]; while left < right && !s.chars().nth(right).unwrap().is_alphanumeric() [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Decrementing left pointer causes underflow.
Incrementing right pointer goes out of bounds.
✗ Incorrect
Increment left pointer to skip non-alphanumeric from start, decrement right pointer to skip from end.
5fill in blank
hardFill all three blanks to compare characters ignoring case and move pointers inward.
DSA Rust
if s.chars().nth(left).unwrap().to_ascii_lowercase() != s.chars().nth(right).unwrap().to_ascii_lowercase() { return false; } left [1]; right [2]; } return [3];
Attempts:
3 left
💡 Hint
Common Mistakes
Returning false at the end instead of true.
Moving pointers in wrong directions.
✗ Incorrect
Move left pointer forward, right pointer backward, and return true if all matched.
