Bird
Raised Fist0
DSA Typescriptprogramming~20 mins

Palindrome Detection in DSA Typescript - Practice Problems & Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
šŸŽ–ļø
Palindrome Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ā“ Predict Output
intermediate
2:00remaining
Output of palindrome check function
What is the output of this TypeScript code that checks if a string is a palindrome?
DSA Typescript
function isPalindrome(s: string): boolean {
  const cleaned = s.toLowerCase().replace(/[^a-z0-9]/g, '');
  return cleaned === cleaned.split('').reverse().join('');
}

console.log(isPalindrome('Racecar'));
Atrue
Bfalse
CSyntaxError
DTypeError
Attempts:
2 left
šŸ’” Hint
Consider how the string is cleaned and reversed before comparison.
🧠 Conceptual
intermediate
1:30remaining
Understanding palindrome properties
Which of the following statements about palindromes is true?
AA palindrome must have an even number of characters.
BA palindrome reads the same forwards and backwards ignoring case and non-alphanumeric characters.
COnly strings with letters can be palindromes.
DPalindromes are always single words without spaces.
Attempts:
2 left
šŸ’” Hint
Think about common palindrome phrases like 'A man, a plan, a canal, Panama'.
šŸ”§ Debug
advanced
2:00remaining
Identify the error in palindrome function
What error will this TypeScript code produce when checking if '12321' is a palindrome?
DSA Typescript
function checkPalindrome(str: string): boolean {
  const reversed = str.split('').reverse().join('');
  return str === reversed;
}

console.log(checkPalindrome(12321));
ATypeError
BSyntaxError
Cfalse
Dtrue
Attempts:
2 left
šŸ’” Hint
Look at the type of the argument passed to the function.
šŸš€ Application
advanced
2:30remaining
Count palindromic substrings in a string
What is the output of this TypeScript code that counts all palindromic substrings in 'aaa'?
DSA Typescript
function countPalindromicSubstrings(s: string): number {
  let count = 0;
  for (let i = 0; i < s.length; i++) {
    // Odd length palindromes
    let left = i, right = i;
    while (left >= 0 && right < s.length && s[left] === s[right]) {
      count++;
      left--;
      right++;
    }
    // Even length palindromes
    left = i;
    right = i + 1;
    while (left >= 0 && right < s.length && s[left] === s[right]) {
      count++;
      left--;
      right++;
    }
  }
  return count;
}

console.log(countPalindromicSubstrings('aaa'));
A5
B3
C4
D6
Attempts:
2 left
šŸ’” Hint
Count all single letters and palindromes of length 2 and 3.
ā“ Predict Output
expert
3:00remaining
Output of palindrome check with Unicode characters
What is the output of this TypeScript code that checks if a Unicode string is a palindrome?
DSA Typescript
function isUnicodePalindrome(s: string): boolean {
  const normalized = s.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase();
  return normalized === [...normalized].reverse().join('');
}

console.log(isUnicodePalindrome('AƱƱa'));
ASyntaxError
Bfalse
Ctrue
DTypeError
Attempts:
2 left
šŸ’” Hint
Normalization removes accents before comparison.

Practice

(1/5)
1. What does it mean if a string is a palindrome?
easy
A. The string has no spaces
B. The string reads the same forwards and backwards
C. The string contains only letters
D. The string is all uppercase

Solution

  1. Step 1: Understand palindrome definition

    A palindrome is a word or phrase that reads the same forwards and backwards.
  2. Step 2: Compare options with definition

    Only The string reads the same forwards and backwards matches this definition exactly.
  3. Final Answer:

    The string reads the same forwards and backwards -> Option B
  4. Quick Check:

    Palindrome = same forwards and backwards [OK]
Hint: Palindrome means same forwards and backwards [OK]
Common Mistakes:
  • Confusing palindrome with uppercase or letter-only strings
  • Thinking palindrome means no spaces
  • Assuming palindrome means all lowercase
2. Which of the following TypeScript code snippets correctly checks if a string str is a palindrome?
easy
A. return str === str.split().reverse().join();
B. return str === str.reverse();
C. return str === str.split('').reverse().join('');
D. return str === str.split('').reverse();

Solution

  1. Step 1: Understand string reversal in TypeScript

    To reverse a string, split it into characters, reverse the array, then join back.
  2. Step 2: Check each option's correctness

    return str === str.split('').reverse().join(''); uses split(''), reverse(), join('') correctly. Others miss correct methods or arguments.
  3. Final Answer:

    return str === str.split('').reverse().join(''); -> Option C
  4. Quick Check:

    Correct string reversal syntax = return str === str.split('').reverse().join(''); [OK]
Hint: Use split(''), reverse(), join('') to reverse strings [OK]
Common Mistakes:
  • Using reverse() directly on string (not an array)
  • Using split() without arguments returns whole string as one element
  • Forgetting to join array back to string
3. What will be the output of this TypeScript code?
function isPalindrome(s: string): boolean {
  const cleaned = s.toLowerCase().replace(/[^a-z0-9]/g, '');
  return cleaned === cleaned.split('').reverse().join('');
}
console.log(isPalindrome('A man, a plan, a canal: Panama'));
medium
A. true
B. false
C. SyntaxError
D. undefined

Solution

  1. Step 1: Clean the string

    The string is converted to lowercase and non-alphanumeric characters removed, resulting in 'amanaplanacanalpanama'.
  2. Step 2: Check palindrome condition

    This cleaned string equals its reverse, so function returns true.
  3. Final Answer:

    true -> Option A
  4. Quick Check:

    Cleaned string equals reversed = true [OK]
Hint: Clean string before checking palindrome for accurate result [OK]
Common Mistakes:
  • Not cleaning string before palindrome check
  • Assuming spaces or punctuation affect palindrome
  • Confusing true/false output
4. Find the error in this palindrome check function:
function checkPalindrome(str: string): boolean {
  const reversed = str.split('').reverse();
  return str === reversed;
}
medium
A. reverse() does not work on strings
B. Function missing return type
C. split('') is incorrect usage
D. reversed is an array, not a string

Solution

  1. Step 1: Analyze reversed variable type

    reversed is an array after split and reverse, not a string.
  2. Step 2: Compare string with array

    Comparing string to array returns false always; need to join array back to string.
  3. Final Answer:

    reversed is an array, not a string -> Option D
  4. Quick Check:

    Compare string to string, not array [OK]
Hint: Join reversed array back to string before comparing [OK]
Common Mistakes:
  • Comparing string directly to array
  • Forgetting to join reversed array
  • Assuming split('') returns string
5. You want to check if a sentence is a palindrome ignoring spaces, punctuation, and case. Which approach is best?
hard
A. Convert to lowercase, remove non-alphanumeric chars, then compare with reversed
B. Compare original string with reversed string directly
C. Remove spaces only, then compare
D. Convert to uppercase and compare with reversed uppercase

Solution

  1. Step 1: Understand palindrome ignoring spaces and punctuation

    We must clean the string by removing spaces and punctuation and normalize case.
  2. Step 2: Choose correct cleaning and comparison

    Convert to lowercase, remove non-alphanumeric chars, then compare with reversed cleans string by removing non-alphanumeric characters and lowercases it before comparing with reversed.
  3. Final Answer:

    Convert to lowercase, remove non-alphanumeric chars, then compare with reversed -> Option A
  4. Quick Check:

    Clean and normalize before palindrome check [OK]
Hint: Clean string fully before palindrome check for accuracy [OK]
Common Mistakes:
  • Only removing spaces but not punctuation
  • Comparing without case normalization
  • Assuming uppercase conversion alone is enough
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard