Reported August 2024
Ciscodynamic programming

Longest Palindromic Subarray

Reported by candidates from Cisco's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Cisco OA. Under 2s to a working solution.
Founder's read

Cisco's August OA included a classic string problem: find the longest palindromic subarray. You're looking at a substring that reads the same forwards and backwards, and you need to return the longest one. This isn't about subsequences (that's easier). It's about contiguous characters. The pattern is dynamic programming, though a few approaches work. If you blank on the DP table during the live assessment, StealthCoder will show you the recurrence and the fill order so you don't lose points.

Pattern and pitfall

The core insight is that a substring is palindromic if its first and last characters match AND the substring between them is palindromic. That recursive structure becomes a DP table where dp[i][j] = true if s[i:j+1] is a palindrome. Build it smartly: iterate by substring length, not by indices alone. Common trap: candidates forget to track the longest palindrome found so far, then return the wrong substring. Another trap: O(n^3) brute force with naive palindrome checks. The DP approach is O(n^2) time and space. During your OA, if the logic goes fuzzy, StealthCoder will surface the exact DP transition and initialization so you can code it without guessing.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Longest Palindromic Subarray 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 StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as longest palindromic substring. If you have time before the OA, drill that.

⏵ The honest play

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 Palindromic Subarray FAQ

Is this asking for the substring or just the length?+

Most OA versions ask for the actual substring. Read the output requirement carefully in the first 30 seconds. If the problem says 'return the longest palindromic substring', it's the string itself, not the length. Edge case: if there are multiple palindromes of the same max length, return any one.

Can I use the expand-around-center trick instead of DP?+

Yes. For each position (and each pair of adjacent positions for even-length palindromes), expand outwards while characters match. Also O(n^2) time, O(1) space. Cleaner code for some people. Both are acceptable. DP is more textbook.

What's the trick to avoid TLE on large strings?+

O(n^2) is the expected complexity for this problem. If the input is under 1000 characters, you're safe. If it exceeds that, Manacher's algorithm exists (O(n)), but Cisco's OA likely won't require it. Don't optimize prematurely.

How do I handle single characters and two-character edge cases?+

Every single character is a palindrome. Seed your DP with dp[i][i] = true. For length 2, check if s[i] == s[i+1]. These are base cases. Missing them costs you on small test cases.

Should I worry about case sensitivity or special characters?+

The problem text wasn't provided, so check the examples carefully. Most OA versions treat the input as-is (case-sensitive). Don't add preprocessing unless the examples show you should. Stick to the spec.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Cisco.

OA at Cisco?
Invisible during screen share
Get it