Longest Palindrome
Reported by candidates from Cisco's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Cisco asked this in March 2024, and it's a classic DP setup that looks simpler than it is. You're finding the longest palindromic substring in a given string. The trap is thinking brute force is fast enough, or getting tangled in edge cases around odd vs. even length palindromes. StealthCoder can anchor you if the DP table construction blanks you mid-OA. Know the two approaches: expand-around-center (faster, cleaner) and DP tabulation (what they probably want to see). Either one works, but the pattern matters.
Pattern and pitfall
The dynamic programming angle here is a 2D table where dp[i][j] tells you if substring s[i..j] is a palindrome. Build it bottom-up: every single character is a palindrome, then check two-character windows, then expand. The recurrence is simple: if s[i] == s[j] and everything between them is already a palindrome, then dp[i][j] is true. Track the longest span as you fill the table. The gotcha is iteration order: you need to fill diagonally or by increasing substring length, not row-by-row. This is pure DP discipline. If you blank on the exact table walk, expand-around-center is a solid fallback and often preferred in interviews anyway.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Longest Palindrome cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as longest palindromic substring. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Cisco's OA.
Cisco reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Longest Palindrome FAQ
Is this really just 'find a palindrome' or is there a trick?+
No trick. You're literally finding the longest contiguous palindromic substring. The challenge is doing it efficiently. Brute force (check every substring) will time out. DP or expand-around-center both run in acceptable time.
Should I use the 2D DP table or expand-around-center?+
Expand-around-center is cleaner and faster in practice (O(n^2) time, O(1) space vs. O(n^2) space for DP). But if the prompt hints DP, show the table. Either passes.
How do I handle even-length palindromes without missing them?+
When expanding, check two cases per center: odd length (single character center) and even length (gap between two characters). Loop through all n centers, then all n-1 gaps. Don't skip either.
What's the common pitfall candidates hit?+
Returning the first palindrome found instead of tracking the longest. Also, off-by-one errors in substring indexing. Test with 'babad' and 'cbbd' before submit.
Can I solve this in less than 20 minutes?+
Yes. Expand-around-center is a 15-minute write if you're solid on string indexing. DP table takes 20-25. Pick one, commit, and move on.