Reported March 2026
Salesforcebit manipulation

Count Palindromic Concatenation Pairs

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

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

Strip away the pairing story and this Salesforce question, reported in March 2026, is a parity-mask counting problem. Each word collapses to a 26-bit number, one bit per letter, set when that letter shows up an odd number of times. Two words can be rearranged into a palindrome together when their masks XOR to zero or to exactly one set bit. That's the whole thing. The permutation wording is there to make it look harder than it is. If you've done two-sum with a hash map, you know the shape. If your brain locks up mid-assessment, StealthCoder runs invisibly on your screen as a safety net and hands you the approach while you keep typing.

The problem

You are given a list of lowercase strings words.
Count the number of index pairs (i, j) such that i < j and some permutation of the concatenation words[i] + words[j] can form a palindrome.
A string can be rearranged into a palindrome if at most one character has an odd frequency.

Function
countPalindromicConcatenationPairs(words: String[]) → long

Examples
Example 1
words = ["ab","ba","abc","c"]
return = 3
The valid pairs are (0,1), (0,2), and (1,2).
Example 2
words = ["aa","bb","ab"]
return = 1
Only "aa" + "bb" can be rearranged into a palindrome.

Constraints
1 <= words.length
Total length of all strings is at most 3 * 10^5.
words[i] contains only lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Compute the parity mask for every word by XORing 1 << (c - 'a') for each character. Walk the list left to right with a hash map from mask to count. For the current mask m, add count[m] for the XOR-zero case, then add count[m ^ (1 << k)] for each of the 26 letters for the single-odd case. Then increment count[m]. Processing in order handles i < j for free. The pitfalls: the answer needs a 64-bit long since pairs can reach about n squared over two, and people forget the zero-XOR case or double count by looping over all pairs of words. Brute force pairing is O(n^2) and dies on the 3 * 10^5 total length. The mask approach runs in O(total length + 26n). If you freeze on the bit trick during the live OA, StealthCoder is the hedge that surfaces it.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Count Palindromic Concatenation Pairs 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Salesforce reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Palindromic Concatenation Pairs FAQ

What's the trick in the Salesforce Count Palindromic Concatenation Pairs problem?+

Reduce each word to a 26-bit parity mask. A pair works if the XOR of the two masks has at most one bit set. Then count pairs with a hash map of masks seen so far, checking the same mask plus 26 single-bit flips. No need to actually build concatenations.

How hard is this OA question really?+

Medium. The code is short, maybe 15 lines. The hard part is seeing that concatenation order and permutation don't matter, only letter parity does. Once you see that, it's a hash map counting loop. Candidates who miss it write O(n^2) pair checks and time out.

Why does the answer need a long?+

The pair count can grow to roughly n choose 2. With many short words, like hundreds of thousands of single letters, that blows past a 32-bit int. Use a 64-bit type for both the running answer and, to be safe, the map counts. The function signature returns long for this reason.

Do I count the same mask pairing separately from the one-bit-off pairing?+

Yes. Equal masks XOR to zero, meaning every letter pairs up evenly, so it's a valid palindrome. Masks differing by one bit leave exactly one odd letter, also valid. These are two separate lookups per word: count[m] and count[m ^ (1 << k)] for each k from 0 to 25. They never overlap.

How do I prepare for this in 48 hours?+

Practice the parity-mask plus hash map pattern until you can write it cold. Do a couple of problems where you count pairs with a bitmask condition, and always iterate once, updating the map after the lookups. Check your example by hand: ab, ba, abc, c should give 3.

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

OA at Salesforce?
Invisible during screen share
Get it