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 Javascript
let left = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Starting left pointer at 1 skips the first character.
Using s.length or s.length - 1 for left pointer start causes out of range or wrong start.
✗ 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 Javascript
let right = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Using s.length causes index out of range.
Starting right pointer at 0 means only checking the first character.
✗ Incorrect
The right pointer should start at the last character index, which is s.length - 1.
3fill in blank
hardFix the error in the while loop condition to continue while left is less than right.
DSA Javascript
while ([1] < right) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using right < right is always false, loop never runs.
Using left + 1 < right causes skipping 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 the left and right pointers.
DSA Javascript
while (left < right && !s[left].match(/[1]/)) left++; while (left < right && !s[right].match(/[2]/)) right--;
Attempts:
3 left
💡 Hint
Common Mistakes
Using [^a-zA-Z0-9] matches non-alphanumeric, which is opposite of what we want here.
Using only [a-z] misses digits and uppercase letters.
✗ Incorrect
We want to skip characters that are NOT alphanumeric, so we check if current character does NOT match alphanumeric pattern.
5fill in blank
hardFill all three blanks to compare characters ignoring case and move pointers accordingly.
DSA Javascript
if (s[left].toLowerCase() [1] s[right].toLowerCase()) { return false; } left[2]; right[3];
Attempts:
3 left
💡 Hint
Common Mistakes
Using === instead of !== causes wrong palindrome check.
Incrementing right pointer or decrementing left pointer reverses logic.
✗ Incorrect
If characters are not equal ignoring case, return false. Otherwise, move left pointer forward and right pointer backward.
