EASYasked at 4 companies

Longest Palindrome

A easy-tier problem at 56% community acceptance, tagged with Hash Table, String, Greedy. Reported in interviews at HP and 3 others.

Founder's read

Longest Palindrome is asked frequently at HP, Akamai, Walmart Labs, and Oracle, yet it trips up candidates who overthink it. The problem asks you to build the longest palindrome from a given set of characters. The acceptance rate sits at 56 percent, which looks deceptive; most who fail either misread the constraint or abandon the greedy approach mid-solution. This is the kind of problem where the obvious trick works perfectly, but you need to see it under pressure. If this hits your live OA and you blank on how character frequencies map to palindrome length, StealthCoder surfaces the solution in seconds, invisible to the proctor.

Companies asking
4
Difficulty
EASY
Acceptance
56%

Companies that ask "Longest Palindrome"

If this hits your live OA

Longest Palindrome is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.

Get StealthCoder
What this means

The trap is thinking you need to rearrange or match characters symmetrically in real time. You don't. Count the frequency of each character using a hash table. For every character with frequency f, you can use floor(f / 2) pairs on each side of the palindrome. Add 1 to the total if any character has an odd frequency, so you can place one in the center. Greedy wins: take the maximum contribution from every character and sum. Common failures happen when candidates try to build the palindrome string itself or miss that a single odd-frequency character can occupy the center. The trick is purely mathematical. This problem tests whether you can recognize a greedy counting problem hiding inside string language. StealthCoder hedges the scenario where pattern recognition fails under time pressure.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Longest Palindrome recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Palindrome interview FAQ

Why is the acceptance rate only 56% if this is marked Easy?+

Most failures stem from misreading the problem as a rearrangement task or trying to construct the actual palindrome. Candidates also forget that you can use at most one character with odd frequency in the center. The algorithm itself is straightforward once the insight lands.

Is Greedy actually the right strategy here?+

Yes. Greedy is optimal because every pair of characters contributes equally to palindrome length, and you want to maximize total pairs. Using a hash table to count, then greedily taking floor(frequency / 2) pairs from each character, guarantees the longest result.

What's the relationship between Hash Table and this problem?+

Hash Table is your first step: count character frequencies in O(n) time and O(26) space for lowercase letters. Without fast frequency lookup, you can't apply the greedy logic. It's a dependency, not just a tag.

Do I actually build the palindrome string, or just return the length?+

Most versions ask for length only, which makes the solution trivial once you see it. Check the exact problem statement on the platform. If you must return the string itself, construct it by writing each character floor(frequency / 2) times, then the highest-frequency odd character in the middle.

Is this still asked at Walmart Labs and Oracle during real interviews?+

Yes, it appears in their intake assessments. The problem is old and simple enough to serve as a warm-up or a speed check rather than a differentiation question. Don't sleep on it, but also don't spend 20 minutes overthinking.

Want the actual problem statement? View "Longest Palindrome" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.