Check Pangram and Longest Palindromic Substring
Filed under IBM
Free read 1 of 3Confirm if spaces and punctuation should be ignored for the pangram check and if uppercase/lowercase letters are treated as equivalent.
The question
Given a string, check whether it is a pangram (contains every letter of the English alphabet at least once) and find the longest palindromic substring within it.
Constraints
- String length n is between 1 and 1000.
- String may contain uppercase and lowercase letters, spaces, and punctuation.
Examples
- Input
- s = "babad"
- Output
- Pangram: False, Longest Palindrome: "bab" (or "aba")
- Why
- Does not contain all letters. Longest palindrome is length 3.
Approach
Confirm if spaces and punctuation should be ignored for the pangram check and if uppercase/lowercase letters are treated as equivalent.
Check all unique alphabetic characters using a set for pangram. For palindromes, check all possible substrings for palindrome property in O(n^3) time.
Use a set of size 26 for pangram. For the longest palindromic substring, use dynamic programming or expand-around-center approach in O(n^2) time.
Empty strings, single-character strings, and strings with no palindromes longer than 1.
Tips
- What they are testing: Test with full alphabet sentences for pangram, and strings with no repeating characters or all identical characters for palindromes.
- Common mistake: Case sensitivity when checking pangrams; ensure all characters are converted to lowercase first.
Related IBM questions
Collected from public candidate posts and coding forums. Updated Nov 2026.