Reported December 2025
Motivebacktracking

Generate Palindromic Permutations

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

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

The mistake that sinks a first attempt on this Motive OA, reported in December 2025, is permuting the whole string and filtering for palindromes. With length up to 14 that's a time bomb, and it spits out duplicates too. The real task is Generate Palindromic Permutations: return every distinct palindrome using all characters, in lexicographic order, or an empty array if none exists. It's a counting plus backtracking problem in disguise. If you blank halfway through the live assessment, StealthCoder runs invisibly on your desktop and gives you a working solution to check yourself against.

The problem

Given a lowercase English string s, return every distinct palindrome that can be formed using all of its characters, in lexicographic order. Return an empty array when none exists.

Function
generatePalindromes(s: String) → String[]

Examples
Example 1
s = "aabb"
return = ["abba","baab"]
Example 2
s = "abc"
return = []

Constraints
1 <= s.length <= 14.
s contains lowercase English letters only.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to build only half the palindrome. Count characters first. If more than one character has an odd count, return an empty array. Otherwise, the odd character (if any) becomes the middle, and you take half of each count to form a multiset of at most 7 letters. Backtrack over that multiset by iterating letters in sorted order and decrementing counts, so duplicates never appear and output comes out lexicographic for free. At each full half, mirror it around the middle. The common pitfall is using a set to dedupe after generating all permutations, which blows up the runtime and misses the point. Another slip is forgetting that odd-length strings need exactly one odd count, while even-length strings need zero. Check both cases. StealthCoder is your hedge if the backtracking with count decrements slips out of your head under the clock.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Generate Palindromic Permutations 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Motive's OA.

Motive reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Generate Palindromic Permutations FAQ

What's the trick to Generate Palindromic Permutations?+

Count letters, reject if more than one has an odd count, then backtrack only over half the letters. Mirror each half around the optional middle character. You never generate invalid strings, so there's no filtering step at all.

How hard is this one really?+

Medium. The idea is simple once you see the half-string approach. Most people lose time on duplicates and ordering. If you iterate sorted letters with a count map, both problems disappear without extra code.

How do I avoid duplicate palindromes?+

Don't use a set of full permutations. Backtrack on a count map of distinct letters instead of on indices. Each recursion level picks a letter type once, so equal letters never create the same string twice.

Why is the output already in lexicographic order?+

Because you loop over letters from a to z at each position of the half. The left half then comes out in sorted order, and the mirrored right half is fully determined by it, so the whole palindrome ordering matches.

How do I prepare for this in 48 hours?+

Write the solution from scratch twice. Cover the count check, the middle character, and the backtracking on a count map. Then test with aabb, abc, a, and aaa. Those four inputs hit every branch of the logic.

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

OA at Motive?
Invisible during screen share
Get it